1 diff -urN bristuff-0.3.0-PRE-1o/zaphfc/Makefile zaphfc_0.3.0-PRE-1o_florz-12/Makefile
2 --- bristuff-0.3.0-PRE-1o/zaphfc/Makefile 2006-02-09 10:11:05.000000000 +0100
3 +++ zaphfc_0.3.0-PRE-1o_florz-12/Makefile 2006-05-02 03:24:31.000000000 +0200
5 -KINCLUDES = /usr/src/linux/include
7 +KINCLUDES = $(KSRC)include
8 BRISTUFFBASE = $(shell dirname `pwd`)
10 ZAP = $(shell [ -f $(BRISTUFFBASE)/zaptel/zaptel.h ] && echo "-I$(BRISTUFFBASE)/zaptel")
11 -RTAI = $(shell [ -f /usr/realtime/include/rtai.h ] && echo "-DRTAITIMING -I/usr/realtime/include")
15 -CFLAGS+=-I. $(ZAP) $(RTAI) -O2 -g -Wall -DBUILDING_TONEZONE
16 +CFLAGS+=-I. $(ZAP) -O2 -g -Wall -DBUILDING_TONEZONE
17 CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
19 -KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP) $(RTAI) -Wall
20 +KFLAGS=-D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer -O2 -Wall -I$(KINCLUDES) $(ZAP) -Wall
21 KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
22 KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
25 zaphfc.ko: zaphfc.c zaphfc.h
28 - @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
29 - make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) ZAP=$(ZAP) modules
30 + @if ! [ -d $(KSRC) ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
31 + make -C $(KSRC) SUBDIRS=$(PWD) ZAP=$(ZAP) modules
33 install: install$(BUILDVER)
35 diff -urN bristuff-0.3.0-PRE-1o/zaphfc/zaphfc.c zaphfc_0.3.0-PRE-1o_florz-12/zaphfc.c
36 --- bristuff-0.3.0-PRE-1o/zaphfc/zaphfc.c 2006-04-25 15:38:47.000000000 +0200
37 +++ zaphfc_0.3.0-PRE-1o_florz-12/zaphfc.c 2006-05-02 03:24:31.000000000 +0200
40 * Klaus-Peter Junghanns <kpj@junghanns.net>
42 + * Copyright (C) 2004, 2005, 2006 Florian Zumbiehl <florz@gmx.de>
43 + * - support for slave mode of the HFC-S chip which allows it to
44 + * sync its sample clock to an external source/another HFC chip
45 + * - support for "interrupt bundling" (let only one card generate
46 + * 8 kHz timing interrupt no matter how many cards there are
48 + * - interrupt loss tolerant b channel handling
50 * This program is free software and may be modified and
51 - * distributed under the terms of the GNU Public License.
52 + * distributed under the terms of the GNU General Public License.
56 #include <linux/kernel.h>
57 #include <linux/module.h>
61 -#include <rtai_sched.h>
62 -#include <rtai_fifos.h>
64 #include <linux/pci.h>
65 #include <linux/init.h>
66 #include <linux/interrupt.h>
71 +#define log2(n) ffz(~(n))
75 #define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
77 static int hfc_dev_count = 0;
78 static int modes = 0; // all TE
80 +static int sync_slave = 0; // all master
81 +static int timer_card = 0;
82 +static int jitterbuffer = 1;
83 static struct pci_dev *multi_hfc = NULL;
84 static spinlock_t registerlock = SPIN_LOCK_UNLOCKED;
86 -void hfc_shutdownCard(struct hfc_card *hfctmp) {
87 - unsigned long flags;
89 - if (hfctmp == NULL) {
93 - if (hfctmp->pci_io == NULL) {
97 - spin_lock_irqsave(&hfctmp->lock,flags);
99 +void hfc_shutdownCard1(struct hfc_card *hfctmp) {
100 printk(KERN_INFO "zaphfc: shutting down card at %p.\n",hfctmp->pci_io);
102 /* Clear interrupt mask */
103 hfctmp->regs.int_m2 = 0;
104 hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
106 - /* Reset pending interrupts */
107 - hfc_inb(hfctmp, hfc_INT_S1);
108 + /* Remove interrupt handler */
109 + free_irq(hfctmp->irq,hfctmp);
112 +void hfc_shutdownCard2(struct hfc_card *hfctmp) {
113 + unsigned long flags;
115 - /* Wait for interrupts that might still be pending */
116 - spin_unlock_irqrestore(&hfctmp->lock, flags);
117 - set_current_state(TASK_UNINTERRUPTIBLE);
118 - schedule_timeout((30 * HZ) / 1000); // wait 30 ms
119 spin_lock_irqsave(&hfctmp->lock,flags);
121 - /* Remove interrupt handler */
123 - free_irq(hfctmp->irq, hfctmp);
125 + /* Reset pending interrupts */
126 + hfc_inb(hfctmp, hfc_INT_S1);
128 /* Soft-reset the card */
129 hfc_outb(hfctmp, hfc_CIRM, hfc_CIRM_RESET); // softreset on
132 pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, 0); // disable memio and bustmaster
134 - if (hfctmp->fifomem != NULL) {
135 - kfree(hfctmp->fifomem);
136 + if (hfctmp->fifos != NULL) {
137 + free_pages((unsigned long)hfctmp->fifos,log2(hfc_FIFO_MEM_SIZE_PAGES));
139 iounmap((void *) hfctmp->pci_io);
140 hfctmp->pci_io = NULL;
141 @@ -128,11 +121,24 @@
142 spin_unlock_irqrestore(&hfctmp->lock,flags);
143 if (hfctmp->ztdev != NULL) {
144 zt_unregister(&hfctmp->ztdev->span);
145 - kfree(hfctmp->ztdev);
146 + vfree(hfctmp->ztdev);
147 printk(KERN_INFO "unregistered from zaptel.\n");
151 +void hfc_shutdownCard(struct hfc_card *hfctmp) {
152 + if (hfctmp == NULL) {
156 + if (hfctmp->pci_io == NULL) {
160 + hfc_shutdownCard1(hfctmp);
161 + hfc_shutdownCard2(hfctmp);
164 void hfc_resetCard(struct hfc_card *hfctmp) {
167 @@ -176,14 +182,14 @@
168 hfctmp->regs.ctmt = hfc_CTMT_TRANSB1 | hfc_CTMT_TRANSB2; // all bchans are transparent , no freaking hdlc
169 hfc_outb(hfctmp, hfc_CTMT, hfctmp->regs.ctmt);
171 - hfctmp->regs.int_m1 = 0;
172 + hfctmp->regs.int_m1=hfc_INTS_L1STATE;
173 + if(hfctmp->cardno==timer_card){
174 + hfctmp->regs.int_m2=hfc_M2_PROC_TRANS;
176 + hfctmp->regs.int_m1|=hfc_INTS_DREC;
177 + hfctmp->regs.int_m2=0;
179 hfc_outb(hfctmp, hfc_INT_M1, hfctmp->regs.int_m1);
182 - hfctmp->regs.int_m2 = 0;
184 - hfctmp->regs.int_m2 = hfc_M2_PROC_TRANS;
186 hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
188 /* Clear already pending ints */
190 hfctmp->regs.sctrl = 3 | hfc_SCTRL_NONE_CAP | hfc_SCTRL_MODE_TE; /* set tx_lo mode, error in datasheet ! */
193 - hfctmp->regs.mst_mode = hfc_MST_MODE_MASTER; /* HFC Master Mode */
194 hfc_outb(hfctmp, hfc_MST_MODE, hfctmp->regs.mst_mode);
195 + hfc_outb(hfctmp, hfc_MST_EMOD, hfctmp->regs.mst_emod);
197 hfc_outb(hfctmp, hfc_SCTRL, hfctmp->regs.sctrl);
198 hfctmp->regs.sctrl_r = 3;
200 hfc_outb(hfctmp, hfc_CIRM, 0x80 | 0x40); // bit order
202 /* Finally enable IRQ output */
204 hfctmp->regs.int_m2 |= hfc_M2_IRQ_ENABLE;
205 hfc_outb(hfctmp, hfc_INT_M2, hfctmp->regs.int_m2);
208 /* clear pending ints */
209 hfc_inb(hfctmp, hfc_INT_S1);
210 @@ -228,374 +232,219 @@
211 spin_unlock(®isterlock);
214 -static void hfc_btrans(struct hfc_card *hfctmp, char whichB) {
215 - // we are called with irqs disabled from the irq handler
216 - int count, maxlen, total;
217 - unsigned char *f1, *f2;
218 - unsigned short *z1, *z2, newz1;
222 - f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F1);
223 - f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1TX_F2);
224 - z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z1 + (*f1 * 4));
225 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1TX_Z2 + (*f1 * 4));
227 - f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F1);
228 - f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2TX_F2);
229 - z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z1 + (*f1 * 4));
230 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2TX_Z2 + (*f1 * 4));
233 - freebytes = *z2 - *z1;
234 - if (freebytes <= 0) {
235 - freebytes += hfc_B_FIFO_SIZE;
237 - count = ZT_CHUNKSIZE;
240 - if (freebytes < count) {
242 - /* only spit out this warning once per second to not make things worse! */
243 - if (hfctmp->clicks > 100) {
244 - printk(KERN_CRIT "zaphfc: bchan tx fifo full, dropping audio! (z1=%d, z2=%d)\n",*z1,*z2);
245 - hfctmp->clicks = 0;
250 - maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z1;
251 - if (maxlen > count) {
254 - newz1 = *z1 + total;
255 - if (newz1 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) { newz1 -= hfc_B_FIFO_SIZE; }
256 +/*===========================================================================*/
259 - memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + *z1),hfctmp->ztdev->chans[0].writechunk, maxlen);
261 - memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + *z1),hfctmp->ztdev->chans[1].writechunk, maxlen);
268 - memcpy((char *)(hfctmp->fifos + hfc_FIFO_B1TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[0].writechunk+maxlen, count);
270 - memcpy((char *)(hfctmp->fifos + hfc_FIFO_B2TX_ZOFF + hfc_B_SUB_VAL),hfctmp->ztdev->chans[1].writechunk+maxlen, count);
273 +#if hfc_B_FIFO_SIZE%ZT_CHUNKSIZE
274 +#error hfc_B_FIFO_SIZE is not a multiple of ZT_CHUNKSIZE even though the code assumes this
277 +static void hfc_dch_init(struct hfc_card *hfctmp){
278 + struct dch *chtmp=&hfctmp->dch;
280 - *z1 = newz1; /* send it now */
281 + chtmp->rx.f1.p=(u8 *)(hfctmp->fifos+hfc_FIFO_DRX_F1);
282 + chtmp->rx.f2.v=0x1f;
283 + chtmp->rx.f2.z2.v=0x1ff;
285 -// 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);
287 + chtmp->tx.f1.p=(u8 *)(hfctmp->fifos+hfc_FIFO_DTX_F1);
288 + chtmp->tx.f1.v=0x1f;
289 + chtmp->tx.f1.z1.v=0x1ff;
290 + chtmp->tx.f2.p=(u8 *)(hfctmp->fifos+hfc_FIFO_DTX_F2);
293 -static void hfc_brec(struct hfc_card *hfctmp, char whichB) {
294 - // we are called with irqs disabled from the irq handler
295 - int count, maxlen, drop;
296 - volatile unsigned char *f1, *f2;
297 - volatile unsigned short *z1, *z2, newz2;
301 - f1 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F1);
302 - f2 = (char *)(hfctmp->fifos + hfc_FIFO_B1RX_F2);
303 - z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z1 + (*f1 * 4));
304 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
306 - f1 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F1);
307 - f2 = (char *)(hfctmp->fifos + hfc_FIFO_B2RX_F2);
308 - z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z1 + (*f1 * 4));
309 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
311 +static void hfc_bch_init(struct hfc_card *hfctmp){
312 + struct bch *chtmp=&hfctmp->bch;
316 - bytes += hfc_B_FIFO_SIZE;
318 - count = ZT_CHUNKSIZE;
320 - if (bytes < ZT_CHUNKSIZE) {
322 - 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);
327 + chtmp->fill_fifo=0;
329 - /* allowing the buffering of hfc_BCHAN_BUFFER bytes of audio data works around irq jitter */
330 - if (bytes > hfc_BCHAN_BUFFER + ZT_CHUNKSIZE) {
331 - /* if the system is too slow to handle it, we will have to drop it all (except 1 zaptel chunk) */
332 - drop = bytes - ZT_CHUNKSIZE;
334 - /* only spit out this warning once per second to not make things worse! */
335 - if (hfctmp->clicks > 100) {
336 - printk(KERN_CRIT "zaphfc: dropped audio (z1=%d, z2=%d, wanted %d got %d, dropped %d).\n",*z1,*z2,count,bytes,drop);
337 - hfctmp->clicks = 0;
339 - /* hm, we are processing the b chan data tooooo slowly... let's drop the lost audio */
340 - newz2 = *z2 + drop;
341 - if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
342 - newz2 -= hfc_B_FIFO_SIZE;
346 + chtmp->rx.c[0].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B1RX_Z1+0x1f*4);
347 + chtmp->rx.c[0].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B1RX_ZOFF);
348 + chtmp->rx.c[1].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B2RX_Z1+0x1f*4);
349 + chtmp->rx.c[1].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B2RX_ZOFF);
350 + chtmp->rx.z2=hfc_B_SUB_VAL;
354 - maxlen = (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL) - *z2;
355 - if (maxlen > count) {
359 - memcpy(hfctmp->ztdev->chans[0].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + *z2), maxlen);
361 - memcpy(hfctmp->ztdev->chans[1].readchunk,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + *z2), maxlen);
363 - newz2 = *z2 + count;
364 - if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
365 - newz2 -= hfc_B_FIFO_SIZE;
366 + chtmp->tx.c[0].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B1TX_Z1+0x1f*4);
367 + chtmp->tx.c[0].z2p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B1TX_Z2+0x1f*4);
368 + chtmp->tx.c[0].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B1TX_ZOFF);
369 + chtmp->tx.c[0].filled=0;
370 + chtmp->tx.c[1].z1p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B2TX_Z1+0x1f*4);
371 + chtmp->tx.c[1].z2p=(unsigned short *)(hfctmp->fifos+hfc_FIFO_B2TX_Z2+0x1f*4);
372 + chtmp->tx.c[1].fifo_base=(char *)(hfctmp->fifos+hfc_FIFO_B2TX_ZOFF);
373 + chtmp->tx.c[1].filled=0;
374 + chtmp->tx.z1=hfc_B_SUB_VAL;
377 + hfc_dch_init(hfctmp);
379 + chtmp->initialized=0;
382 +static int hfc_bch_check(struct hfc_card *hfctmp){
383 + struct bch *chtmp=&hfctmp->bch;
387 + chtmp->tx.c[x].filled=(chtmp->tx.z1-*chtmp->tx.c[x].z2p+hfc_B_FIFO_SIZE)%hfc_B_FIFO_SIZE;
388 + chtmp->rx.c[x].filled=(*chtmp->rx.c[x].z1p-chtmp->rx.z2+hfc_B_FIFO_SIZE)%hfc_B_FIFO_SIZE;
396 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B1RX_Z2 + (*f1 * 4));
397 - memcpy(hfctmp->ztdev->chans[0].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B1RX_ZOFF + hfc_B_SUB_VAL), count);
399 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_B2RX_Z2 + (*f1 * 4));
400 - memcpy(hfctmp->ztdev->chans[1].readchunk + maxlen,(char *)(hfctmp->fifos + hfc_FIFO_B2RX_ZOFF + hfc_B_SUB_VAL), count);
402 - newz2 = *z2 + count;
403 - if (newz2 >= (hfc_B_FIFO_SIZE + hfc_B_SUB_VAL)) {
404 - newz2 -= hfc_B_FIFO_SIZE;
405 + if(chtmp->fill_fifo){
407 + chtmp->checkcnt%=ZT_CHUNKSIZE;
408 + r=!chtmp->checkcnt;
410 + x=chtmp->tx.c[0].filled-chtmp->tx.c[1].filled;
411 + if(abs(x-chtmp->tx.diff)>1){
412 + printk(KERN_CRIT "zaphfc[%d]: tx sync changed: %d, %d\n",hfctmp->cardno,chtmp->tx.c[0].filled,chtmp->tx.c[1].filled);
415 + r=chtmp->tx.c[0].filled<=ZT_CHUNKSIZE*jitterbuffer&&chtmp->tx.c[1].filled<=ZT_CHUNKSIZE*jitterbuffer;
420 +#define hfc_bch_inc_z(a,b) (a)=((a)-hfc_B_SUB_VAL+(b))%hfc_B_FIFO_SIZE+hfc_B_SUB_VAL
423 - zt_ec_chunk(&hfctmp->ztdev->chans[0], hfctmp->ztdev->chans[0].readchunk, hfctmp->ztdev->chans[0].writechunk);
425 - zt_ec_chunk(&hfctmp->ztdev->chans[1], hfctmp->ztdev->chans[1].readchunk, hfctmp->ztdev->chans[1].writechunk);
426 +static void hfc_bch_tx(struct hfc_card *hfctmp){
427 + struct bch *chtmp=&hfctmp->bch;
431 + memcpy((void *)(chtmp->tx.c[x].fifo_base+chtmp->tx.z1),hfctmp->ztdev->chans[x].writechunk,ZT_CHUNKSIZE);
432 + hfc_bch_inc_z(chtmp->tx.z1,ZT_CHUNKSIZE);
433 + if(chtmp->fill_fifo){
434 + chtmp->fill_fifo--;
435 + }else if(chtmp->tx.c[0].filled<=1||chtmp->tx.c[1].filled<=1){
436 + chtmp->fill_fifo=jitterbuffer;
437 + if(chtmp->initialized)
438 + printk(KERN_CRIT "zaphfc[%d]: b channel buffer underrun: %d, %d\n",hfctmp->cardno,chtmp->tx.c[0].filled,chtmp->tx.c[1].filled);
441 + if(!chtmp->fill_fifo)
442 + for(x=0;x<2;x++)*chtmp->tx.c[x].z1p=chtmp->tx.z1;
446 -static void hfc_dtrans(struct hfc_card *hfctmp) {
447 - // we are called with irqs disabled from the irq handler
448 +static void hfc_bch_rx(struct hfc_card *hfctmp){
449 + struct bch *chtmp=&hfctmp->bch;
451 - int count, maxlen, total;
452 - unsigned char *f1, *f2, newf1;
453 - unsigned short *z1, *z2, newz1;
454 - int frames, freebytes;
456 - if (hfctmp->ztdev->chans[2].bytes2transmit == 0) {
458 + x=chtmp->rx.c[0].filled-chtmp->rx.c[1].filled;
459 + if(abs(x-chtmp->rx.diff)>1){
460 + printk(KERN_CRIT "zaphfc[%d]: rx sync changed: %d, %d\n",hfctmp->cardno,chtmp->rx.c[0].filled,chtmp->rx.c[1].filled);
464 - f1 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F1);
465 - f2 = (char *)(hfctmp->fifos + hfc_FIFO_DTX_F2);
466 - z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
467 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z2 + (*f1 * 4));
469 - frames = (*f1 - *f2) & hfc_FMASK;
471 - frames += hfc_MAX_DFRAMES + 1;
472 + if(chtmp->rx.c[0].filled>=ZT_CHUNKSIZE&&chtmp->rx.c[1].filled>=ZT_CHUNKSIZE){
473 + if((chtmp->rx.c[0].filled>=ZT_CHUNKSIZE*(jitterbuffer+2)&&chtmp->rx.c[1].filled>=ZT_CHUNKSIZE*(jitterbuffer+2))||!chtmp->initialized){
474 + if(chtmp->initialized)
475 + printk(KERN_CRIT "zaphfc[%d]: b channel buffer overflow: %d, %d\n",hfctmp->cardno,chtmp->rx.c[0].filled,chtmp->rx.c[1].filled);
476 + hfc_bch_inc_z(chtmp->rx.z2,chtmp->rx.c[0].filled-chtmp->rx.c[0].filled%ZT_CHUNKSIZE-ZT_CHUNKSIZE);
477 + chtmp->initialized=1;
480 + memcpy(hfctmp->ztdev->chans[x].readchunk,(void *)(chtmp->rx.c[x].fifo_base+chtmp->rx.z2),ZT_CHUNKSIZE);
481 + zt_ec_chunk(&hfctmp->ztdev->chans[x],hfctmp->ztdev->chans[x].readchunk,hfctmp->ztdev->chans[x].writechunk);
483 + hfc_bch_inc_z(chtmp->rx.z2,ZT_CHUNKSIZE);
487 - if (frames >= hfc_MAX_DFRAMES) {
488 - printk(KERN_CRIT "zaphfc: dchan tx fifo total number of frames exceeded!\n");
491 +/*===========================================================================*/
493 - freebytes = *z2 - *z1;
494 - if (freebytes <= 0) {
495 - freebytes += hfc_D_FIFO_SIZE;
497 - count = hfctmp->ztdev->chans[2].bytes2transmit;
500 - if (freebytes < count) {
501 - printk(KERN_CRIT "zaphfc: dchan tx fifo not enough free bytes! (z1=%d, z2=%d)\n",*z1,*z2);
505 - newz1 = (*z1 + count) & hfc_ZMASK;
506 - newf1 = ((*f1 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); // next frame
510 - printk(KERN_CRIT "zaphfc: card %d TX [ ", hfctmp->cardno);
511 - for (x=0; x<count; x++) {
512 +static void hfc_dch_tx(struct hfc_card *hfctmp){
513 + struct dch *chtmp=&hfctmp->dch;
517 + if(hfctmp->ztdev->chans[2].bytes2transmit){
519 + printk(KERN_CRIT "zaphfc[%d]: card TX [ ",hfctmp->cardno);
520 + for(x=0;x<hfctmp->ztdev->chans[2].bytes2transmit;x++){
521 printk("%#2x ",hfctmp->dtransbuf[x]);
523 - if (hfctmp->ztdev->chans[2].eoftx == 1) {
524 - printk("] %d bytes\n", count);
526 - printk("..] %d bytes\n", count);
529 - maxlen = hfc_D_FIFO_SIZE - *z1;
530 - if (maxlen > count) {
532 + printk("] %d bytes\n",hfctmp->ztdev->chans[2].bytes2transmit);
534 - memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF + *z1),hfctmp->ztdev->chans[2].writechunk, maxlen);
537 - memcpy((char *)(hfctmp->fifos + hfc_FIFO_DTX_ZOFF),(char *)(hfctmp->ztdev->chans[2].writechunk + maxlen), count);
538 + tx_f2_v=*chtmp->tx.f2.p;
539 + if(!(tx_f2_v-chtmp->tx.f1.v+hfc_MAX_DFRAMES+1-1)&(hfc_MAX_DFRAMES+1-1)){
540 + printk(KERN_CRIT "zaphfc[%d]: dchan tx fifo total number of frames exceeded!\n",hfctmp->cardno);
542 + 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){
543 + printk(KERN_CRIT "zaphfc[%d]: dchan tx fifo not enough space for frame!\n",hfctmp->cardno);
545 + chtmp->tx.f1.v=((chtmp->tx.f1.v+1)&hfc_MAX_DFRAMES)|(hfc_MAX_DFRAMES+1);
546 + x=min(hfctmp->ztdev->chans[2].bytes2transmit,hfc_D_FIFO_SIZE-chtmp->tx.f1.z1.v);
547 + memcpy(hfctmp->fifos+hfc_FIFO_DTX_ZOFF+chtmp->tx.f1.z1.v,hfctmp->ztdev->chans[2].writechunk,x);
548 + memcpy(hfctmp->fifos+hfc_FIFO_DTX_ZOFF,hfctmp->ztdev->chans[2].writechunk+x,hfctmp->ztdev->chans[2].bytes2transmit-x);
549 + *(volatile u16 *)(hfctmp->fifos+hfc_FIFO_DTX_Z2+chtmp->tx.f1.v*4)=chtmp->tx.f1.z1.v;
550 + chtmp->tx.f1.z1.v=(chtmp->tx.f1.z1.v+hfctmp->ztdev->chans[2].bytes2transmit+hfc_D_FIFO_SIZE)&(hfc_D_FIFO_SIZE-1);
551 + *(volatile u16 *)(hfctmp->fifos+hfc_FIFO_DTX_Z1+chtmp->tx.f1.v*4)=chtmp->tx.f1.z1.v;
552 + *chtmp->tx.f1.p=chtmp->tx.f1.v;
559 - if (hfctmp->ztdev->chans[2].eoftx == 1) {
561 - z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DTX_Z1 + (*f1 * 4));
563 - hfctmp->ztdev->chans[2].eoftx = 0;
565 -// printk(KERN_CRIT "zaphfc: dchan tx fifo (f1=%d, f2=%d, z1=%d, z2=%d)\n",(*f1) & hfc_FMASK,(*f2) & hfc_FMASK, *z1, *z2);
569 -/* receive a complete hdlc frame, skip broken or short frames */
570 -static void hfc_drec(struct hfc_card *hfctmp) {
571 - int count=0, maxlen=0, framelen=0;
572 - unsigned char *f1, *f2, *crcstat;
573 - unsigned short *z1, *z2, oldz2, newz2;
574 +static void hfc_dch_rx(struct hfc_card *hfctmp){
575 + struct dch *chtmp=&hfctmp->dch;
578 hfctmp->ztdev->chans[2].bytes2receive=0;
579 - hfctmp->ztdev->chans[2].eofrx = 0;
581 - /* put the received data into the zaptel buffer
582 - we'll call zt_receive() later when the timer fires. */
583 - f1 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F1);
584 - f2 = (char *)(hfctmp->fifos + hfc_FIFO_DRX_F2);
586 - if (*f1 == *f2) return; /* nothing received, strange eh? */
588 - z1 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z1 + (*f2 * 4));
589 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
591 - /* calculate length of frame, including 2 bytes CRC and 1 byte STAT */
595 - count += hfc_D_FIFO_SIZE; /* ring buffer wrapped */
600 - crcstat = (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z1);
602 - if ((framelen < 4) || (*crcstat != 0x0)) {
603 - /* the frame is too short for a valid HDLC frame or the CRC is borked */
604 - printk(KERN_CRIT "zaphfc: empty HDLC frame or bad CRC received (framelen = %d, stat = %#x, card = %d).\n", framelen, *crcstat, hfctmp->cardno);
606 - *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
607 - // recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!!
608 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
609 - *z2 = (oldz2 + framelen) & hfc_ZMASK;
610 - hfctmp->drecinframe = 0;
611 - hfctmp->regs.int_drec--;
612 - /* skip short or broken frames */
613 - hfctmp->ztdev->chans[2].bytes2receive = 0;
617 - count -= 1; /* strip STAT */
618 - hfctmp->ztdev->chans[2].eofrx = 1;
620 - if (count + *z2 <= hfc_D_FIFO_SIZE) {
623 - maxlen = hfc_D_FIFO_SIZE - *z2;
624 + hfctmp->ztdev->chans[2].eofrx=0;
625 + if(*chtmp->rx.f1.p==chtmp->rx.f2.v){
626 + hfctmp->regs.int_drec=0;
628 + 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;
630 + printk(KERN_CRIT "zaphfc[%d]: empty HDLC frame received.\n",hfctmp->cardno);
632 + u16 x=min(size,(u16)(hfc_D_FIFO_SIZE-chtmp->rx.f2.z2.v));
633 + memcpy(hfctmp->drecbuf,hfctmp->fifos+hfc_FIFO_DRX_ZOFF+chtmp->rx.f2.z2.v,x);
634 + memcpy(hfctmp->drecbuf+x,hfctmp->fifos+hfc_FIFO_DRX_ZOFF,size-x);
635 + if(hfctmp->drecbuf[size-1]){
636 + printk(KERN_CRIT "zaphfc[%d]: received d channel frame with bad CRC.\n",hfctmp->cardno);
638 + hfctmp->ztdev->chans[2].bytes2receive=size-1;
639 + hfctmp->ztdev->chans[2].eofrx=1;
642 + chtmp->rx.f2.z2.v=(chtmp->rx.f2.z2.v+size)&(hfc_D_FIFO_SIZE-1);
643 + chtmp->rx.f2.v=((chtmp->rx.f2.v+1)&hfc_MAX_DFRAMES)|(hfc_MAX_DFRAMES+1);
646 - /* copy first part */
647 - memcpy(hfctmp->drecbuf, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF + *z2), maxlen);
648 - hfctmp->ztdev->chans[2].bytes2receive += maxlen;
652 - /* ring buffer wrapped, copy rest from start of d fifo */
653 - memcpy(hfctmp->drecbuf + maxlen, (char *)(hfctmp->fifos + hfc_FIFO_DRX_ZOFF), count);
654 - hfctmp->ztdev->chans[2].bytes2receive += count;
659 - newz2 = (oldz2 + framelen) & hfc_ZMASK;
660 - *f2 = ((*f2 + 1) & hfc_MAX_DFRAMES) | (hfc_MAX_DFRAMES + 1); /* NEXT!!! */
661 - /* recalculate z2, because Z2 is a function of F2 Z2(F2) and we INCed F2!!! */
662 - z2 = (unsigned short *)(hfctmp->fifos + hfc_FIFO_DRX_Z2 + (*f2 * 4));
664 - hfctmp->drecinframe = 0;
665 - hfctmp->regs.int_drec--;
669 +/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
672 static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
674 static void hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
676 struct hfc_card *hfctmp = dev_id;
677 - unsigned long flags = 0;
678 - unsigned char stat;
680 -static void hfc_service(struct hfc_card *hfctmp) {
682 + struct hfc_card *hfctmp2;
683 struct zt_hfc *zthfc;
684 - unsigned char s1, s2, l1state;
685 + unsigned char stat, s1, s2, l1state;
686 + unsigned long flags;
687 + unsigned long flags2=0;
703 if (!hfctmp->pci_io) {
704 printk(KERN_WARNING "%s: IO-mem disabled, cannot handle interrupt\n",
718 - /* we assume a few things in this irq handler:
719 - - the hfc-pci will only generate "timer" irqs (proc/non-proc)
720 - - we need to use every 8th IRQ (to generate 1khz timing)
722 - - if we use rtai for timing the hfc-pci will not generate ANY irq,
723 - instead rtai will call this "fake" irq with a 1khz realtime timer. :)
724 - - rtai will directly service the card, not like it used to by triggering
729 spin_lock_irqsave(&hfctmp->lock, flags);
730 stat = hfc_inb(hfctmp, hfc_STATUS);
732 if ((stat & hfc_STATUS_ANYINT) == 0) {
733 // maybe we are sharing the irq
734 spin_unlock_irqrestore(&hfctmp->lock,flags);
741 s1 = hfc_inb(hfctmp, hfc_INT_S1);
742 s2 = hfc_inb(hfctmp, hfc_INT_S2);
744 @@ -625,18 +472,10 @@
749 - sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
751 sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 ACTIVATED (G%d)", hfctmp->cardno, l1state);
756 - sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d) [realtime]", hfctmp->cardno, l1state);
758 sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] layer 1 DEACTIVATED (G%d)", hfctmp->cardno, l1state);
762 hfc_outb(hfctmp, hfc_STATES, hfc_STATES_ACTIVATE | hfc_STATES_DO_ACTION | hfc_STATES_NT_G2_G3);
763 @@ -650,18 +489,10 @@
768 - sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
770 sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 ACTIVATED (F%d)", hfctmp->cardno, l1state);
775 - sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d) [realtime]", hfctmp->cardno, l1state);
777 sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] layer 1 DEACTIVATED (F%d)", hfctmp->cardno, l1state);
781 hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
784 if (s1 & hfc_INTS_DREC) {
786 - hfctmp->regs.int_drec++;
787 + hfctmp->regs.int_drec = 1;
788 // mr. zapata there is something for you!
789 // printk(KERN_CRIT "d chan rx\n");
791 @@ -692,14 +523,10 @@
792 // B1 chan TX (bit 0)
797 - s2 |= hfc_M2_PROC_TRANS;
800 if (s2 & hfc_M2_PMESEL) {
801 // kaboom irq (bit 7)
802 - printk(KERN_CRIT "zaphfc: sync lost, pci performance too low. you might have some cpu throtteling enabled.\n");
803 + // printk(KERN_CRIT "zaphfc: sync lost, pci performance too low. you might have some cpu throtteling enabled.\n");
805 if (s2 & hfc_M2_GCI_MON_REC) {
806 // RxR monitor channel (bit 2)
807 @@ -707,32 +534,30 @@
808 if (s2 & hfc_M2_GCI_I_CHG) {
809 // GCI I-change (bit 1)
811 - if (s2 & hfc_M2_PROC_TRANS) {
812 + if((s2&hfc_M2_PROC_TRANS)&&(hfctmp->cardno==timer_card)){
813 // processing/non-processing transition (bit 0)
816 - if (hfctmp->ticks > 7) {
817 - // welcome to zaptel timing :)
822 + hfctmp=hfc_dev_list;
824 + if(hfctmp->active){
825 + if(hfctmp!=hfctmp2)spin_lock_irqsave(&hfctmp->lock, flags2);
826 + if(hfc_bch_check(hfctmp)){
827 if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
828 // clear dchan buffer
829 + // memset(hfctmp->drecbuf, 0x0, sizeof(hfctmp->drecbuf));
831 hfctmp->ztdev->chans[2].bytes2transmit = 0;
832 hfctmp->ztdev->chans[2].maxbytes2transmit = hfc_D_FIFO_SIZE;
834 zt_transmit(&(hfctmp->ztdev->span));
836 - hfc_btrans(hfctmp,1);
837 - hfc_btrans(hfctmp,2);
838 - hfc_dtrans(hfctmp);
839 + hfc_bch_tx(hfctmp);
840 + hfc_dch_tx(hfctmp);
843 - hfc_brec(hfctmp,1);
844 - hfc_brec(hfctmp,2);
845 - if (hfctmp->regs.int_drec > 0) {
846 + hfc_bch_rx(hfctmp);
847 + if (hfctmp->regs.int_drec) {
848 // dchan data to read
850 + hfc_dch_rx(hfctmp);
851 if (hfctmp->ztdev->chans[2].bytes2receive > 0) {
853 printk(KERN_CRIT "zaphfc: card %d RX [ ", hfctmp->cardno);
854 @@ -757,19 +582,18 @@
855 if (hfctmp->ztdev->span.flags & ZT_FLAG_RUNNING) {
856 zt_receive(&(hfctmp->ztdev->span));
862 + if(hfctmp!=hfctmp2)spin_unlock_irqrestore(&hfctmp->lock,flags2);
864 + hfctmp=hfctmp->next;
871 spin_unlock_irqrestore(&hfctmp->lock,flags);
873 return IRQ_RETVAL(1);
879 @@ -826,22 +650,21 @@
881 alreadyrunning = span->flags & ZT_FLAG_RUNNING;
883 - if (!alreadyrunning) {
884 - span->chans[2].flags &= ~ZT_FLAG_HDLC;
885 - span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
887 - span->flags |= ZT_FLAG_RUNNING;
888 + if (alreadyrunning) return 0;
890 - hfctmp->ticks = -2;
891 - hfctmp->clicks = 0;
892 - hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
893 - hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
897 + span->chans[2].flags &= ~ZT_FLAG_HDLC;
898 + span->chans[2].flags |= ZT_FLAG_BRIDCHAN;
900 + span->flags |= ZT_FLAG_RUNNING;
902 + hfctmp->ticks = -2;
903 + hfctmp->regs.fifo_en = hfc_FIFOEN_D | hfc_FIFOEN_B1 | hfc_FIFOEN_B2;
904 + hfc_outb(hfctmp, hfc_FIFO_EN, hfctmp->regs.fifo_en);
906 + hfc_bch_init(hfctmp);
907 // drivers, start engines!
908 hfc_outb(hfctmp, hfc_STATES, hfc_STATES_DO_ACTION | hfc_STATES_ACTIVATE);
915 sprintf(zthfc->span.name, "ZTHFC%d", hfc_dev_count + 1);
916 if (hfctmp->regs.nt_mode == 1) {
918 - sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT] [realtime]", hfc_dev_count + 1);
920 sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [NT]", hfc_dev_count + 1);
924 - sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE] [realtime]", hfc_dev_count + 1);
926 sprintf(zthfc->span.desc, "HFC-S PCI A ISDN card %d [TE]", hfc_dev_count + 1);
930 zthfc->span.spanconfig = zthfc_spanconfig;
936 -#define TICK_PERIOD 1000000
937 -#define TICK_PERIOD2 1000000000
938 -#define TASK_PRIORITY 1
939 -#define STACK_SIZE 10000
941 -static RT_TASK rt_task;
942 -static struct hfc_card *rtai_hfc_list[hfc_MAX_CARDS];
943 -static unsigned char rtai_hfc_counter = 0;
945 -static void rtai_register_hfc(struct hfc_card *hfctmp) {
946 - rtai_hfc_list[rtai_hfc_counter++] = hfctmp;
949 -static void rtai_loop(int t) {
952 - for (i=0; i < rtai_hfc_counter; i++) {
953 - if (rtai_hfc_list[i] != NULL)
954 - hfc_service(rtai_hfc_list[i]);
956 - rt_task_wait_period();
961 int hfc_findCards(int pcivendor, int pcidevice, char *vendor_name, char *card_name) {
963 struct hfc_card *hfctmp = NULL;
968 - hfctmp = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
969 + hfctmp = vmalloc(sizeof(struct hfc_card));
971 - printk(KERN_WARNING "zaphfc: unable to kmalloc!\n");
972 + printk(KERN_WARNING "zaphfc: unable to vmalloc!\n");
973 pci_disable_device(tmp);
977 memset(hfctmp, 0x0, sizeof(struct hfc_card));
978 spin_lock_init(&hfctmp->lock);
981 hfctmp->pcidev = tmp;
982 hfctmp->pcibus = tmp->bus->number;
983 hfctmp->pcidevfn = tmp->devfn;
984 @@ -982,49 +772,39 @@
985 hfctmp->pci_io = (char *) tmp->resource[1].start;
986 if (!hfctmp->pci_io) {
987 printk(KERN_WARNING "zaphfc: no iomem!\n");
990 pci_disable_device(tmp);
995 - hfctmp->fifomem = kmalloc(65536, GFP_KERNEL);
996 - if (!hfctmp->fifomem) {
997 - printk(KERN_WARNING "zaphfc: unable to kmalloc fifomem!\n");
1000 + hfctmp->fifos=(void *)__get_free_pages(GFP_KERNEL,log2(hfc_FIFO_MEM_SIZE_PAGES));
1001 + if (!hfctmp->fifos) {
1002 + printk(KERN_WARNING "zaphfc: unable to __get_free_pages fifomem!\n");
1004 pci_disable_device(tmp);
1008 - memset(hfctmp->fifomem, 0x0, 65536);
1009 - hfctmp->fifos = (void *)(((ulong) hfctmp->fifomem) & ~0x7FFF) + 0x8000;
1010 pci_write_config_dword(hfctmp->pcidev, 0x80, (u_int) virt_to_bus(hfctmp->fifos));
1011 hfctmp->pci_io = ioremap((ulong) hfctmp->pci_io, 256);
1015 - /* we need no stinking irq */
1018 if (request_irq(hfctmp->irq, &hfc_interrupt, SA_INTERRUPT | SA_SHIRQ, "zaphfc", hfctmp)) {
1019 printk(KERN_WARNING "zaphfc: unable to register irq\n");
1020 - kfree(hfctmp->fifomem);
1022 + free_pages((unsigned long)hfctmp->fifos,log2(hfc_FIFO_MEM_SIZE_PAGES));
1024 iounmap((void *) hfctmp->pci_io);
1025 pci_disable_device(tmp);
1032 - rtai_register_hfc(hfctmp);
1035 - "zaphfc: %s %s configured at mem %lx fifo %lx(%#x) IRQ %d HZ %d\n",
1036 + "zaphfc: %s %s configured at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n",
1037 vendor_name, card_name,
1038 - (unsigned long) hfctmp->pci_io,
1039 - (unsigned long) hfctmp->fifos,
1040 + (u_int) hfctmp->pci_io,
1041 + (u_int) hfctmp->fifos,
1042 (u_int) virt_to_bus(hfctmp->fifos),
1044 pci_write_config_word(hfctmp->pcidev, PCI_COMMAND, PCI_COMMAND_MEMORY); // enable memio
1045 @@ -1041,11 +821,21 @@
1046 hfctmp->regs.nt_mode = 0;
1049 - zthfc = kmalloc(sizeof(struct zt_hfc),GFP_KERNEL);
1050 + if(sync_slave&(1<<hfc_dev_count)){
1051 + printk(KERN_INFO "zaphfc: Card %d configured for slave mode\n",hfc_dev_count);
1052 + hfctmp->regs.mst_mode=hfc_MST_MODE_SLAVE|hfc_MST_MODE_F0_LONG_DURATION;
1053 + hfctmp->regs.mst_emod=hfc_MST_EMOD_SLOW_CLOCK_ADJ;
1055 + printk(KERN_INFO "zaphfc: Card %d configured for master mode\n",hfc_dev_count);
1056 + hfctmp->regs.mst_mode=hfc_MST_MODE_MASTER|hfc_MST_MODE_F0_LONG_DURATION;
1057 + hfctmp->regs.mst_emod=0;
1060 + zthfc = vmalloc(sizeof(struct zt_hfc));
1062 - printk(KERN_CRIT "zaphfc: unable to kmalloc!\n");
1063 + printk(KERN_CRIT "zaphfc: unable to vmalloc!\n");
1064 hfc_shutdownCard(hfctmp);
1070 @@ -1071,7 +861,6 @@
1071 memset(hfctmp->btransbuf[1], 0x0, sizeof(hfctmp->btransbuf[1]));
1072 hfctmp->ztdev->chans[1].writechunk = hfctmp->btransbuf[1];
1075 hfc_registerCard(hfctmp);
1076 hfc_resetCard(hfctmp);
1077 tmp = pci_find_device(pcivendor, pcidevice, multi_hfc);
1078 @@ -1079,58 +868,42 @@
1084 int init_module(void) {
1087 - RTIME tick_period;
1088 - for (i=0; i < hfc_MAX_CARDS; i++) {
1089 - rtai_hfc_list[i] = NULL;
1090 + if(jitterbuffer<1){
1091 + printk(KERN_INFO "zaphfc: invalid jitterbuffer size specified: %d - changing to minimum of 1\n",jitterbuffer);
1093 + }else if(jitterbuffer>500){
1094 + printk(KERN_INFO "zaphfc: invalid jitterbuffer size specified: %d - changing to maximum of 500\n",jitterbuffer);
1097 - rt_set_periodic_mode();
1100 + printk(KERN_INFO "zaphfc: jitterbuffer size: %d\n",jitterbuffer);
1101 while (id_list[i].vendor_id) {
1103 hfc_findCards(id_list[i].vendor_id, id_list[i].device_id, id_list[i].vendor_name, id_list[i].card_name);
1107 - for (i=0; i < hfc_MAX_CARDS; i++) {
1108 - if (rtai_hfc_list[i]) {
1110 - "zaphfc: configured %d at mem %#x fifo %#x(%#x) for realtime servicing\n",
1111 - rtai_hfc_list[i]->cardno,
1112 - (u_int) rtai_hfc_list[i]->pci_io,
1113 - (u_int) rtai_hfc_list[i]->fifos,
1114 - (u_int) virt_to_bus(rtai_hfc_list[i]->fifos));
1118 - rt_task_init(&rt_task, rtai_loop, 1, STACK_SIZE, TASK_PRIORITY, 0, 0);
1119 - tick_period = start_rt_timer(nano2count(TICK_PERIOD));
1120 - rt_task_make_periodic(&rt_task, rt_get_time() + tick_period, tick_period);
1122 printk(KERN_INFO "zaphfc: %d hfc-pci card(s) in this box.\n", hfc_dev_count);
1126 void cleanup_module(void) {
1127 struct hfc_card *tmpcard;
1130 - rt_task_delete(&rt_task);
1133 printk(KERN_INFO "zaphfc: stop\n");
1134 // spin_lock(®isterlock);
1135 + tmpcard=hfc_dev_list;
1137 + hfc_shutdownCard1(tmpcard);
1138 + tmpcard=tmpcard->next;
1140 while (hfc_dev_list != NULL) {
1141 if (hfc_dev_list == NULL) break;
1142 - hfc_shutdownCard(hfc_dev_list);
1143 + hfc_shutdownCard2(hfc_dev_list);
1144 tmpcard = hfc_dev_list;
1145 hfc_dev_list = hfc_dev_list->next;
1146 if (tmpcard != NULL) {
1150 printk(KERN_INFO "zaphfc: freed one card.\n");
1152 @@ -1141,11 +914,17 @@
1156 -module_param(modes, int, 0600);
1157 +module_param(modes, int, 0400);
1158 module_param(debug, int, 0600);
1159 +module_param(sync_slave, int, 0400);
1160 +module_param(timer_card, int, 0400);
1161 +module_param(jitterbuffer, int, 0400);
1163 MODULE_PARM(modes,"i");
1164 MODULE_PARM(debug,"i");
1165 +MODULE_PARM(sync_slave,"i");
1166 +MODULE_PARM(timer_card,"i");
1167 +MODULE_PARM(jitterbuffer,"i");
1170 MODULE_DESCRIPTION("HFC-S PCI A Zaptel Driver");
1171 @@ -1153,3 +932,6 @@
1172 #ifdef MODULE_LICENSE
1173 MODULE_LICENSE("GPL");
1176 +/* vim:set sw=4: */
1178 diff -urN bristuff-0.3.0-PRE-1o/zaphfc/zaphfc.h zaphfc_0.3.0-PRE-1o_florz-12/zaphfc.h
1179 --- bristuff-0.3.0-PRE-1o/zaphfc/zaphfc.h 2005-02-26 23:30:32.000000000 +0100
1180 +++ zaphfc_0.3.0-PRE-1o_florz-12/zaphfc.h 2005-03-02 20:43:04.000000000 +0100
1181 @@ -135,8 +135,12 @@
1182 /* bits in HFCD_MST_MODE */
1183 #define hfc_MST_MODE_MASTER 0x01
1184 #define hfc_MST_MODE_SLAVE 0x00
1185 +#define hfc_MST_MODE_F0_LONG_DURATION 0x08
1186 /* remaining bits are for codecs control */
1188 +/* bits in HFCD_MST_EMOD */
1189 +#define hfc_MST_EMOD_SLOW_CLOCK_ADJ 0x01
1191 /* bits in HFCD_SCTRL */
1192 #define hfc_SCTRL_B1_ENA 0x01
1193 #define hfc_SCTRL_B2_ENA 0x02
1195 #define hfc_BTRANS_THRESHOLD 128
1196 #define hfc_BTRANS_THRESMASK 0x00
1198 +#define hfc_FIFO_MEM_SIZE_BYTES (32*1024)
1199 +#define hfc_FIFO_MEM_SIZE_PAGES ((hfc_FIFO_MEM_SIZE_BYTES+PAGE_SIZE-1)/PAGE_SIZE)
1203 typedef struct hfc_regs {
1204 @@ -249,20 +256,67 @@
1205 unsigned char connect;
1207 unsigned char mst_mode;
1208 + unsigned char mst_emod;
1209 unsigned char bswapped;
1210 unsigned char nt_mode;
1211 unsigned char int_drec;
1215 + int fill_fifo,checkcnt,initialized;
1219 + volatile u16 *z1p;
1220 + volatile u8 *fifo_base;
1228 + volatile u16 *z1p,*z2p;
1229 + volatile u8 *fifo_base;
1262 typedef struct hfc_card {
1268 unsigned char *pci_io;
1269 - void *fifomem; // start of the shared mem
1270 - volatile void *fifos; // 32k aligned mem for the fifos
1271 + void *fifos; // 32k aligned mem for the fifos
1272 struct hfc_regs regs;
1273 unsigned int pcibus;
1274 unsigned int pcidevfn;
1276 unsigned char brecbuf[2][ZT_CHUNKSIZE];
1277 unsigned char btransbuf[2][ZT_CHUNKSIZE];
1278 unsigned char cardno;
1282 struct hfc_card *next;
1286 struct hfc_card *card;
1290 -#define hfc_BCHAN_BUFFER 8
1291 -#define hfc_MAX_CARDS 8
1292 +/* vim:set sw=4: */