1 Index: dahdi-linux-2.10.0.1/drivers/dahdi/Kbuild
2 ===================================================================
3 --- dahdi-linux-2.10.0.1.orig/drivers/dahdi/Kbuild
4 +++ dahdi-linux-2.10.0.1/drivers/dahdi/Kbuild
5 @@ -13,6 +13,7 @@ obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCT
6 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCTDM24XXP) += wctdm24xxp/
7 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCTE12XP) += wcte12xp/
8 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCTE13XP) += wcte13xp.o
9 +obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_HFCS) += hfcs/
11 wcte13xp-objs := wcte13xp-base.o wcxb_spi.o wcxb.o wcxb_flash.o
12 CFLAGS_wcte13xp-base.o += -I$(src)/oct612x -I$(src)/oct612x/include -I$(src)/oct612x/octdeviceapi -I$(src)/oct612x/octdeviceapi/oct6100api
13 Index: dahdi-linux-2.10.0.1/drivers/dahdi/Kconfig
14 ===================================================================
15 --- dahdi-linux-2.10.0.1.orig/drivers/dahdi/Kconfig
16 +++ dahdi-linux-2.10.0.1/drivers/dahdi/Kconfig
17 @@ -291,4 +291,14 @@ config DAHDI_WCTE11XP
22 + tristate "Support for various HFC-S PCI BRI adapters"
23 + depends on DAHDI && PCI
26 + To compile this driver as a module, choose M here: the
27 + module will be called dahdi_hfcs.
31 source "drivers/dahdi/xpp/Kconfig"
32 Index: dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/base.c
33 ===================================================================
35 +++ dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/base.c
38 + * dahdi_hfcs.c - Dahdi driver for HFC-S PCI A based ISDN BRI cards
40 + * Dahdi rewrite in hardhdlc mode
41 + * Jose A. Deniz <odicha@hotmail.com>
43 + * Copyright (C) 2011, Raoul Bönisch
44 + * Copyright (C) 2009, Jose A. Deniz
45 + * Copyright (C) 2006, headissue GmbH; Jens Wilke
46 + * Copyright (C) 2004 Daniele Orlandi
47 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
49 + * Jens Wilke <jw_vzaphfc@headissue.com>
51 + * Original author of this code is
52 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
54 + * Major rewrite of the driver made by
55 + * Klaus-Peter Junghanns <kpj@junghanns.net>
57 + * This program is free software and may be modified and
58 + * distributed under the terms of the GNU Public License.
60 + * Please read the README file for important infos.
63 +#include <linux/spinlock.h>
64 +#include <linux/init.h>
65 +#include <linux/pci.h>
66 +#include <linux/interrupt.h>
67 +#include <linux/module.h>
68 +#include <linux/moduleparam.h>
69 +#include <linux/version.h>
70 +#include <linux/kernel.h>
71 +#include <linux/delay.h>
72 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
73 +#include <linux/sched.h>
75 +#include <linux/proc_fs.h>
76 +#include <linux/if_arp.h>
78 +#include <dahdi/kernel.h>
80 +#include "dahdi_hfcs.h"
97 +static int nt_modes[hfc_MAX_BOARDS];
98 +static int nt_modes_count;
99 +static int force_l1_up;
100 +static struct proc_dir_entry *hfc_proc_dahdi_hfcs_dir;
111 +#define TRUE (!FALSE)
114 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
115 +#define SET_PROC_DIRENTRY_OWNER(p) do { (p)->owner = THIS_MODULE; } while(0);
117 +#define SET_PROC_DIRENTRY_OWNER(p) do { } while(0);
120 +static DEFINE_PCI_DEVICE_TABLE(hfc_pci_ids) = {
121 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0,
122 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
123 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000,
124 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
125 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006,
126 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
127 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007,
128 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
129 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008,
130 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
131 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009,
132 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
133 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A,
134 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
135 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B,
136 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
137 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C,
138 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
139 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100,
140 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
141 + {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1,
142 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
143 + {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675,
144 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
145 + {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT,
146 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
147 + {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T,
148 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
149 + {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575,
150 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
151 + {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0,
152 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
153 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,
154 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
155 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,
156 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
157 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,
158 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
159 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,
160 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
161 + {PCI_VENDOR_ID_SITECOM, PCI_DEVICE_ID_SITECOM_3069,
162 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
166 +MODULE_DEVICE_TABLE(pci, hfc_pci_ids);
168 +static int __devinit hfc_probe(struct pci_dev *dev
169 + , const struct pci_device_id *ent);
170 +static void __devexit hfc_remove(struct pci_dev *dev);
172 +static struct pci_driver hfc_driver = {
173 + .name = hfc_DRIVER_NAME,
174 + .id_table = hfc_pci_ids,
175 + .probe = hfc_probe,
176 + .remove = __devexit_p(hfc_remove),
179 +/******************************************
181 + ******************************************/
183 +static void hfc_softreset(struct hfc_card *card)
185 + printk(KERN_INFO hfc_DRIVER_PREFIX
191 + * Softreset procedure. Put it on, wait and off again
193 + hfc_outb(card, hfc_CIRM, hfc_CIRM_RESET);
195 + hfc_outb(card, hfc_CIRM, 0);
197 + set_current_state(TASK_UNINTERRUPTIBLE);
198 + schedule_timeout((hfc_RESET_DELAY * HZ) / 1000);
201 +static void hfc_resetCard(struct hfc_card *card)
204 + hfc_outb(card, hfc_INT_M1, card->regs.m1);
207 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
209 + hfc_softreset(card);
211 + card->regs.trm = 0;
212 + hfc_outb(card, hfc_TRM, card->regs.trm);
215 + * Select the non-capacitive line mode for the S/T interface
217 + card->regs.sctrl = hfc_SCTRL_NONE_CAP;
219 + if (card->nt_mode) {
221 + * ST-Bit delay for NT-Mode
223 + hfc_outb(card, hfc_CLKDEL, hfc_CLKDEL_NT);
225 + card->regs.sctrl |= hfc_SCTRL_MODE_NT;
228 + * ST-Bit delay for TE-Mode
230 + hfc_outb(card, hfc_CLKDEL, hfc_CLKDEL_TE);
232 + card->regs.sctrl |= hfc_SCTRL_MODE_TE;
235 + hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
240 + card->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
241 + hfc_outb(card, hfc_SCTRL_E, card->regs.sctrl_e);
244 + * No B-channel enabled at startup
246 + card->regs.sctrl_r = 0;
247 + hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
252 + hfc_outb(card, hfc_MST_MODE, hfc_MST_MODE_MASTER);
255 + * Connect internal blocks
257 + card->regs.connect =
258 + hfc_CONNECT_B1_HFC_from_ST |
259 + hfc_CONNECT_B1_ST_from_HFC |
260 + hfc_CONNECT_B1_GCI_from_HFC |
261 + hfc_CONNECT_B2_HFC_from_ST |
262 + hfc_CONNECT_B2_ST_from_HFC |
263 + hfc_CONNECT_B2_GCI_from_HFC;
264 + hfc_outb(card, hfc_CONNECT, card->regs.connect);
267 + * All bchans are HDLC by default, not useful, actually
268 + * since mode is set during open()
270 + hfc_outb(card, hfc_CTMT, 0);
275 + hfc_outb(card, hfc_CIRM, 0);
278 + * Enable D-rx FIFO. At least one FIFO must be enabled (by specs)
280 + card->regs.fifo_en = hfc_FIFOEN_DRX;
281 + hfc_outb(card, hfc_FIFO_EN, card->regs.fifo_en);
283 + card->late_irqs = 0;
286 + * Clear already pending ints
288 + hfc_inb(card, hfc_INT_S1);
289 + hfc_inb(card, hfc_INT_S2);
292 + * Enable IRQ output
294 + card->regs.m1 = hfc_INTS_DREC | hfc_INTS_L1STATE | hfc_INTS_TIMER;
295 + hfc_outb(card, hfc_INT_M1, card->regs.m1);
297 + card->regs.m2 = hfc_M2_IRQ_ENABLE;
298 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
301 + * Unlocks the states machine
303 + hfc_outb(card, hfc_STATES, 0);
306 + * There's no need to explicitly activate L1 now.
307 + * Activation is managed inside the interrupt routine.
311 +static void hfc_update_fifo_state(struct hfc_card *card)
314 + * I'm not sure if irqsave is needed but there could be a race
315 + * condition since hfc_update_fifo_state could be called from
316 + * both the IRQ handler and the *_(open|close) functions
319 + unsigned long flags;
320 + spin_lock_irqsave(&card->chans[B1].lock, flags);
321 + if (!card->fifo_suspended &&
322 + (card->chans[B1].status == open_framed ||
323 + card->chans[B1].status == open_voice)) {
325 + if (!(card->regs.fifo_en & hfc_FIFOEN_B1RX)) {
326 + card->regs.fifo_en |= hfc_FIFOEN_B1RX;
327 + hfc_clear_fifo_rx(&card->chans[B1].rx);
330 + if (!(card->regs.fifo_en & hfc_FIFOEN_B1TX)) {
331 + card->regs.fifo_en |= hfc_FIFOEN_B1TX;
332 + hfc_clear_fifo_tx(&card->chans[B1].tx);
335 + if (card->regs.fifo_en & hfc_FIFOEN_B1RX)
336 + card->regs.fifo_en &= ~hfc_FIFOEN_B1RX;
337 + if (card->regs.fifo_en & hfc_FIFOEN_B1TX)
338 + card->regs.fifo_en &= ~hfc_FIFOEN_B1TX;
340 + spin_unlock_irqrestore(&card->chans[B1].lock, flags);
342 + spin_lock_irqsave(&card->chans[B2].lock, flags);
343 + if (!card->fifo_suspended &&
344 + (card->chans[B2].status == open_framed ||
345 + card->chans[B2].status == open_voice ||
346 + card->chans[B2].status == sniff_aux)) {
348 + if (!(card->regs.fifo_en & hfc_FIFOEN_B2RX)) {
349 + card->regs.fifo_en |= hfc_FIFOEN_B2RX;
350 + hfc_clear_fifo_rx(&card->chans[B2].rx);
353 + if (!(card->regs.fifo_en & hfc_FIFOEN_B2TX)) {
354 + card->regs.fifo_en |= hfc_FIFOEN_B2TX;
355 + hfc_clear_fifo_tx(&card->chans[B2].tx);
358 + if (card->regs.fifo_en & hfc_FIFOEN_B2RX)
359 + card->regs.fifo_en &= ~hfc_FIFOEN_B2RX;
360 + if (card->regs.fifo_en & hfc_FIFOEN_B2TX)
361 + card->regs.fifo_en &= ~hfc_FIFOEN_B2TX;
363 + spin_unlock_irqrestore(&card->chans[B2].lock, flags);
365 + spin_lock_irqsave(&card->chans[D].lock, flags);
366 + if (!card->fifo_suspended &&
367 + card->chans[D].status == open_framed) {
369 + if (!(card->regs.fifo_en & hfc_FIFOEN_DTX)) {
370 + card->regs.fifo_en |= hfc_FIFOEN_DTX;
372 + card->chans[D].tx.ugly_framebuf_size = 0;
373 + card->chans[D].tx.ugly_framebuf_off = 0;
376 + if (card->regs.fifo_en & hfc_FIFOEN_DTX)
377 + card->regs.fifo_en &= ~hfc_FIFOEN_DTX;
379 + spin_unlock_irqrestore(&card->chans[D].lock, flags);
381 + hfc_outb(card, hfc_FIFO_EN, card->regs.fifo_en);
384 +static inline void hfc_suspend_fifo(struct hfc_card *card)
386 + card->fifo_suspended = TRUE;
388 + hfc_update_fifo_state(card);
391 + * When L1 goes down D rx receives garbage; it is nice to
392 + * clear it to avoid a CRC error on reactivation
393 + * udelay is needed because the FIFO deactivation happens
397 + hfc_clear_fifo_rx(&card->chans[D].rx);
400 + if (debug_level >= 3) {
401 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
403 + "FIFOs suspended\n",
409 +static inline void hfc_resume_fifo(struct hfc_card *card)
411 + card->fifo_suspended = FALSE;
413 + hfc_update_fifo_state(card);
416 + if (debug_level >= 3) {
417 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
425 +static void hfc_check_l1_up(struct hfc_card *card)
427 + if ((!card->nt_mode && card->l1_state != 7)
428 + || (card->nt_mode && card->l1_state != 3)) {
430 + hfc_outb(card, hfc_STATES, hfc_STATES_DO_ACTION |
431 + hfc_STATES_ACTIVATE|
432 + hfc_STATES_NT_G2_G3);
435 + * 0 because this is quite verbose when an inferface is unconnected, jaw
438 + if (debug_level >= 1) {
439 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
441 + "L1 is down, bringing up L1.\n",
449 +/*******************
450 + * Dahdi interface *
451 + *******************/
453 +static int hfc_dahdi_open(struct dahdi_chan *dahdi_chan)
455 + struct hfc_chan_duplex *chan = dahdi_chan->pvt;
456 + struct hfc_card *card = chan->card;
458 + spin_lock(&chan->lock);
460 + switch (chan->number) {
462 + if (chan->status != free &&
463 + chan->status != open_framed) {
464 + spin_unlock(&chan->lock);
467 + chan->status = open_framed;
472 + if (chan->status != free) {
473 + spin_unlock(&chan->lock);
476 + chan->status = open_voice;
480 + chan->open_by_dahdi = TRUE;
481 + try_module_get(THIS_MODULE);
482 + spin_unlock(&chan->lock);
484 + switch (chan->number) {
489 + card->regs.m2 |= hfc_M2_PROC_TRANS;
491 + * Enable transparent mode
493 + card->regs.ctmt |= hfc_CTMT_TRANSB1;
495 + * Reversed bit order
497 + card->regs.cirm |= hfc_CIRM_B1_REV;
499 + * Enable transmission
501 + card->regs.sctrl |= hfc_SCTRL_B1_ENA;
505 + card->regs.sctrl_r |= hfc_SCTRL_R_B1_ENA;
509 + card->regs.m2 |= hfc_M2_PROC_TRANS;
510 + card->regs.ctmt |= hfc_CTMT_TRANSB2;
511 + card->regs.cirm |= hfc_CIRM_B2_REV;
512 + card->regs.sctrl |= hfc_SCTRL_B2_ENA;
513 + card->regs.sctrl_r |= hfc_SCTRL_R_B2_ENA;
519 + * If not already enabled, enable processing transition (8KHz)
522 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
523 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
524 + hfc_outb(card, hfc_CIRM, card->regs.cirm);
525 + hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
526 + hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
528 + hfc_update_fifo_state(card);
530 + printk(KERN_INFO hfc_DRIVER_PREFIX
532 + "chan %s opened as %s.\n",
540 +static int hfc_dahdi_close(struct dahdi_chan *dahdi_chan)
542 + struct hfc_chan_duplex *chan = dahdi_chan->pvt;
543 + struct hfc_card *card = chan->card;
546 + printk(KERN_CRIT hfc_DRIVER_PREFIX
547 + "hfc_dahdi_close called with NULL card\n");
551 + spin_lock(&chan->lock);
553 + if (chan->status == free) {
554 + spin_unlock(&chan->lock);
558 + chan->status = free;
559 + chan->open_by_dahdi = FALSE;
561 + spin_unlock(&chan->lock);
563 + switch (chan->number) {
568 + card->regs.ctmt &= ~hfc_CTMT_TRANSB1;
569 + card->regs.cirm &= ~hfc_CIRM_B1_REV;
570 + card->regs.sctrl &= ~hfc_SCTRL_B1_ENA;
571 + card->regs.sctrl_r &= ~hfc_SCTRL_R_B1_ENA;
575 + card->regs.ctmt &= ~hfc_CTMT_TRANSB2;
576 + card->regs.cirm &= ~hfc_CIRM_B2_REV;
577 + card->regs.sctrl &= ~hfc_SCTRL_B2_ENA;
578 + card->regs.sctrl_r &= ~hfc_SCTRL_R_B2_ENA;
582 + if (card->chans[B1].status == free &&
583 + card->chans[B2].status == free)
584 + card->regs.m2 &= ~hfc_M2_PROC_TRANS;
586 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
587 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
588 + hfc_outb(card, hfc_CIRM, card->regs.cirm);
589 + hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
590 + hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
592 + hfc_update_fifo_state(card);
594 + module_put(THIS_MODULE);
596 + printk(KERN_INFO hfc_DRIVER_PREFIX
598 + "chan %s closed as %s.\n",
606 +static int hfc_dahdi_rbsbits(struct dahdi_chan *chan, int bits)
611 +static int hfc_dahdi_ioctl(struct dahdi_chan *chan,
612 + unsigned int cmd, unsigned long data)
623 +static void hfc_hdlc_hard_xmit(struct dahdi_chan *d_chan)
625 + struct hfc_chan_duplex *chan = d_chan->pvt;
626 + struct hfc_card *card = chan->card;
627 + struct dahdi_hfc *hfccard = card->dahdi_dev;
629 + atomic_inc(&hfccard->hdlc_pending);
633 +static int hfc_dahdi_startup(struct file *file, struct dahdi_span *span)
635 + struct dahdi_hfc *dahdi_hfcs = dahdi_hfc_from_span(span);
636 + struct hfc_card *hfctmp = dahdi_hfcs->card;
637 + int alreadyrunning;
640 + printk(KERN_INFO hfc_DRIVER_PREFIX
642 + "no card for span at startup!\n",
646 + alreadyrunning = span->flags & DAHDI_FLAG_RUNNING;
648 + if (!alreadyrunning)
649 + span->flags |= DAHDI_FLAG_RUNNING;
654 +static int hfc_dahdi_shutdown(struct dahdi_span *span)
659 +static int hfc_dahdi_maint(struct dahdi_span *span, int cmd)
664 +static int hfc_dahdi_chanconfig(struct file *file, struct dahdi_chan *d_chan, int sigtype)
666 + struct hfc_chan_duplex *chan = d_chan->pvt;
667 + struct hfc_card *card = chan->card;
668 + struct dahdi_hfc *hfccard = card->dahdi_dev;
670 + if ((sigtype == DAHDI_SIG_HARDHDLC) && (hfccard->sigchan == d_chan)) {
671 + hfccard->sigactive = 0;
672 + atomic_set(&hfccard->hdlc_pending, 0);
678 +static int hfc_dahdi_spanconfig(struct file *file, struct dahdi_span *span,
679 + struct dahdi_lineconfig *lc)
681 + span->lineconfig = lc->lineconfig;
686 +static const struct dahdi_span_ops hfc_dahdi_span_ops = {
687 + .owner = THIS_MODULE,
688 + .chanconfig = hfc_dahdi_chanconfig,
689 + .spanconfig = hfc_dahdi_spanconfig,
690 + .startup = hfc_dahdi_startup,
691 + .shutdown = hfc_dahdi_shutdown,
692 + .maint = hfc_dahdi_maint,
693 + .rbsbits = hfc_dahdi_rbsbits,
694 + .open = hfc_dahdi_open,
695 + .close = hfc_dahdi_close,
696 + .ioctl = hfc_dahdi_ioctl,
697 + .hdlc_hard_xmit = hfc_hdlc_hard_xmit
700 +static int hfc_dahdi_initialize(struct dahdi_hfc *hfccard)
702 + struct hfc_card *hfctmp = hfccard->card;
705 + hfccard->ddev = dahdi_create_device();
706 + if (!hfccard->ddev)
709 + memset(&hfccard->span, 0x0, sizeof(struct dahdi_span));
714 + * Cards' and channels' names shall contain "ZTHFC"
715 + * as the dahdi-tools look for this string to guess framing.
716 + * We don't want to modify dahdi-tools only in order to change this.
718 + * So we choose for a span name: DAHDI HFC-S formerly known as ZTHFC. :-)
721 + sprintf(hfccard->span.name, "DAHDI_HFCS_FKA_ZTHFC%d", hfctmp->cardnum + 1);
722 + sprintf(hfccard->span.desc,
723 + "HFC-S PCI A ISDN card %d [%s] ",
725 + hfctmp->nt_mode ? "NT" : "TE");
726 + hfccard->span.spantype = hfctmp->nt_mode ? SPANTYPE_DIGITAL_BRI_NT :
727 + SPANTYPE_DIGITAL_BRI_TE;
728 + hfccard->ddev->manufacturer = "Cologne Chips";
729 + hfccard->span.flags = 0;
730 + hfccard->span.ops = &hfc_dahdi_span_ops;
731 + hfccard->ddev->devicetype = kasprintf(GFP_KERNEL, "HFC-S PCI-A ISDN");
732 + hfccard->ddev->location = kasprintf(GFP_KERNEL, "PCI Bus %02d Slot %02d",
733 + hfctmp->pcidev->bus->number,
734 + PCI_SLOT(hfctmp->pcidev->devfn) + 1);
735 + hfccard->span.chans = hfccard->_chans;
736 + hfccard->span.channels = 3;
737 + for (i = 0; i < hfccard->span.channels; i++)
738 + hfccard->_chans[i] = &hfccard->chans[i];
739 + hfccard->span.deflaw = DAHDI_LAW_ALAW;
740 + hfccard->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_CCS;
741 + hfccard->span.offset = 0;
743 + for (i = 0; i < hfccard->span.channels; i++) {
744 + memset(&hfccard->chans[i], 0x0, sizeof(struct dahdi_chan));
746 + sprintf(hfccard->chans[i].name,
747 + "DAHDI_HFCS_FKA_ZTHFC%d/%d/%d",
748 + hfctmp->cardnum + 1, 0, i + 1);
750 + printk(KERN_INFO hfc_DRIVER_PREFIX
754 + hfccard->chans[i].name);
756 + if (i == hfccard->span.channels - 1) {
757 + hfccard->chans[i].sigcap = DAHDI_SIG_HARDHDLC;
758 + hfccard->sigchan = &hfccard->chans[DAHDI_D];
759 + hfccard->sigactive = 0;
760 + atomic_set(&hfccard->hdlc_pending, 0);
762 + hfccard->chans[i].sigcap =
763 + DAHDI_SIG_CLEAR | DAHDI_SIG_DACS;
766 + hfccard->chans[i].chanpos = i + 1;
769 + hfccard->chans[DAHDI_D].readchunk =
770 + hfctmp->chans[D].rx.dahdi_buffer;
772 + hfccard->chans[DAHDI_D].writechunk =
773 + hfctmp->chans[D].tx.dahdi_buffer;
775 + hfccard->chans[DAHDI_D].pvt = &hfctmp->chans[D];
777 + hfccard->chans[DAHDI_B1].readchunk =
778 + hfctmp->chans[B1].rx.dahdi_buffer;
780 + hfccard->chans[DAHDI_B1].writechunk =
781 + hfctmp->chans[B1].tx.dahdi_buffer;
783 + hfccard->chans[DAHDI_B1].pvt = &hfctmp->chans[B1];
785 + hfccard->chans[DAHDI_B2].readchunk =
786 + hfctmp->chans[B2].rx.dahdi_buffer;
788 + hfccard->chans[DAHDI_B2].writechunk =
789 + hfctmp->chans[B2].tx.dahdi_buffer;
791 + hfccard->chans[DAHDI_B2].pvt = &hfctmp->chans[B2];
793 + list_add_tail(&hfccard->span.device_node, &hfccard->ddev->spans);
794 + if (dahdi_register_device(hfccard->ddev, &hfccard->card->pcidev->dev)) {
795 + printk(KERN_NOTICE "Unable to register device with DAHDI\n");
802 +static void hfc_dahdi_transmit(struct hfc_chan_simplex *chan)
804 + hfc_fifo_put(chan, chan->dahdi_buffer, DAHDI_CHUNKSIZE);
807 +static void hfc_dahdi_receive(struct hfc_chan_simplex *chan)
809 + hfc_fifo_get(chan, chan->dahdi_buffer, DAHDI_CHUNKSIZE);
812 +/******************************************
813 + * Interrupt Handler
814 + ******************************************/
816 +static void hfc_handle_timer_interrupt(struct hfc_card *card);
817 +static void hfc_handle_state_interrupt(struct hfc_card *card);
818 +static void hfc_handle_processing_interrupt(struct hfc_card *card);
819 +static void hfc_frame_arrived(struct hfc_chan_duplex *chan);
820 +static void hfc_handle_voice(struct hfc_card *card);
822 +#if (KERNEL_VERSION(2, 6, 24) < LINUX_VERSION_CODE)
823 +static irqreturn_t hfc_interrupt(int irq, void *dev_id)
825 +static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
828 + struct hfc_card *card = dev_id;
829 + unsigned long flags;
833 + printk(KERN_CRIT hfc_DRIVER_PREFIX
834 + "spurious interrupt (IRQ %d)\n",
839 + spin_lock_irqsave(&card->lock, flags);
840 + status = hfc_inb(card, hfc_STATUS);
841 + if (!(status & hfc_STATUS_ANYINT)) {
843 + * maybe we are sharing the irq
845 + spin_unlock_irqrestore(&card->lock, flags);
849 + /* We used to ingore the IRQ when the card was in processing
850 + * state but apparently there is no restriction to access the
851 + * card in such state:
853 + * Joerg Ciesielski wrote:
854 + * > There is no restriction for the IRQ handler to access
855 + * > HFC-S PCI during processing phase. A IRQ latency of 375 us
856 + * > is also no problem since there are no interrupt sources in
857 + * > HFC-S PCI which must be handled very fast.
858 + * > Due to its deep fifos the IRQ latency can be several ms with
859 + * > out the risk of loosing data. Even the S/T state interrupts
860 + * > must not be handled with a latency less than <5ms.
862 + * > The processing phase only indicates that HFC-S PCI is
863 + * > processing the Fifos as PCI master so that data is read and
864 + * > written in the 32k memory window. But there is no restriction
865 + * > to access data in the memory window during this time.
867 + * // if (status & hfc_STATUS_PCI_PROC) {
868 + * // return IRQ_HANDLED;
872 + s1 = hfc_inb(card, hfc_INT_S1);
873 + s2 = hfc_inb(card, hfc_INT_S2);
876 + if (s1 & hfc_INTS_TIMER) {
880 + hfc_handle_timer_interrupt(card);
883 + if (s1 & hfc_INTS_L1STATE) {
885 + * state machine (bit 6)
887 + hfc_handle_state_interrupt(card);
890 + if (s1 & hfc_INTS_DREC) {
892 + * D chan RX (bit 5)
894 + hfc_frame_arrived(&card->chans[D]);
897 + if (s1 & hfc_INTS_B1REC) {
899 + * B1 chan RX (bit 3)
901 + hfc_frame_arrived(&card->chans[B1]);
904 + if (s1 & hfc_INTS_B2REC) {
906 + * B2 chan RX (bit 4)
908 + hfc_frame_arrived(&card->chans[B2]);
911 + if (s1 & hfc_INTS_DTRANS) {
913 + * D chan TX (bit 2)
917 + if (s1 & hfc_INTS_B1TRANS) {
919 + * B1 chan TX (bit 0)
923 + if (s1 & hfc_INTS_B2TRANS) {
925 + * B2 chan TX (bit 1)
932 + if (s2 & hfc_M2_PMESEL) {
934 + * kaboom irq (bit 7)
936 + * CologneChip says:
938 + * the meaning of this fatal error bit is that HFC-S
939 + * PCI as PCI master could not access the PCI bus
940 + * within 125us to finish its data processing. If this
941 + * happens only very seldom it does not cause big
942 + * problems but of course some B-channel or D-channel
943 + * data will be corrupted due to this event.
945 + * Unfortunately this bit is only set once after the
946 + * problem occurs and can only be reseted by a
947 + * software reset. That means it is not easily
948 + * possible to check how often this fatal error
953 + if (!card->sync_loss_reported) {
954 + printk(KERN_CRIT hfc_DRIVER_PREFIX
956 + "sync lost, pci performance too low!\n",
959 + card->sync_loss_reported = TRUE;
963 + if (s2 & hfc_M2_GCI_MON_REC) {
965 + * RxR monitor channel (bit 2)
969 + if (s2 & hfc_M2_GCI_I_CHG) {
971 + * GCI I-change (bit 1)
975 + if (s2 & hfc_M2_PROC_TRANS) {
977 + * processing/non-processing transition (bit 0)
979 + hfc_handle_processing_interrupt(card);
984 + spin_unlock_irqrestore(&card->lock, flags);
986 + return IRQ_HANDLED;
989 +static void hfc_handle_timer_interrupt(struct hfc_card *card)
991 + if (card->ignore_first_timer_interrupt) {
992 + card->ignore_first_timer_interrupt = FALSE;
996 + if ((card->nt_mode && card->l1_state == 3) ||
997 + (!card->nt_mode && card->l1_state == 7)) {
999 + card->regs.ctmt &= ~hfc_CTMT_TIMER_MASK;
1000 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
1002 + hfc_resume_fifo(card);
1006 +static void hfc_handle_state_interrupt(struct hfc_card *card)
1008 + u8 new_state = hfc_inb(card, hfc_STATES) & hfc_STATES_STATE_MASK;
1011 + if (debug_level >= 1) {
1012 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1014 + "layer 1 state = %c%d\n",
1016 + card->nt_mode ? 'G' : 'F',
1021 + if (card->nt_mode) {
1026 + if (new_state == 3) {
1028 + * fix to G3 state (see specs)
1030 + hfc_outb(card, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
1033 + if (new_state == 3 && card->l1_state != 3)
1034 + hfc_resume_fifo(card);
1036 + if (new_state != 3 && card->l1_state == 3)
1037 + hfc_suspend_fifo(card);
1040 + if (new_state == 3) {
1042 + * Keep L1 up... zaptel & libpri expects
1043 + * a always up L1...
1044 + * Enable only when using an unpatched libpri
1046 + * Are we still using unpatched libpri? Is this tested at runtime???
1047 + * Does it only affect zaptel or DAHDI, too?
1050 + if (force_l1_up) {
1051 + hfc_outb(card, hfc_STATES,
1052 + hfc_STATES_DO_ACTION |
1053 + hfc_STATES_ACTIVATE|
1054 + hfc_STATES_NT_G2_G3);
1058 + if (new_state == 7 && card->l1_state != 7) {
1060 + * TE is now active, schedule FIFO activation after
1061 + * some time, otherwise the first frames are lost
1064 + card->regs.ctmt |= hfc_CTMT_TIMER_50 |
1065 + hfc_CTMT_TIMER_CLEAR;
1066 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
1069 + * Activating the timer firest an
1070 + * interrupt immediately, we
1071 + * obviously need to ignore it
1073 + card->ignore_first_timer_interrupt = TRUE;
1076 + if (new_state != 7 && card->l1_state == 7) {
1078 + * TE has become inactive, disable FIFO
1080 + hfc_suspend_fifo(card);
1084 + card->l1_state = new_state;
1087 +static void hfc_handle_processing_interrupt(struct hfc_card *card)
1089 + int available_bytes = 0;
1092 + * Synchronize with the first enabled channel
1094 + if (card->regs.fifo_en & hfc_FIFOEN_B1RX)
1095 + available_bytes = hfc_fifo_used_rx(&card->chans[B1].rx);
1096 + if (card->regs.fifo_en & hfc_FIFOEN_B2RX)
1097 + available_bytes = hfc_fifo_used_rx(&card->chans[B2].rx);
1099 + available_bytes = -1;
1101 + if ((available_bytes == -1 && card->ticks == 8) ||
1102 + available_bytes >= DAHDI_CHUNKSIZE + hfc_RX_FIFO_PRELOAD) {
1105 + if (available_bytes > DAHDI_CHUNKSIZE*2 + hfc_RX_FIFO_PRELOAD) {
1106 + card->late_irqs++;
1108 + * we are out of sync, clear fifos, jaw
1110 + hfc_clear_fifo_rx(&card->chans[B1].rx);
1111 + hfc_clear_fifo_tx(&card->chans[B1].tx);
1112 + hfc_clear_fifo_rx(&card->chans[B2].rx);
1113 + hfc_clear_fifo_tx(&card->chans[B2].tx);
1116 + if (debug_level >= 4) {
1117 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1119 + "late IRQ, %d bytes late\n",
1122 + (DAHDI_CHUNKSIZE +
1123 + hfc_RX_FIFO_PRELOAD));
1127 + hfc_handle_voice(card);
1135 +static void hfc_handle_voice(struct hfc_card *card)
1137 + struct dahdi_hfc *hfccard = card->dahdi_dev;
1138 + int frame_left, res;
1139 + unsigned char buf[hfc_HDLC_BUF_LEN];
1140 + unsigned int size = sizeof(buf) / sizeof(buf[0]);
1143 + if (card->chans[B1].status != open_voice &&
1144 + card->chans[B2].status != open_voice)
1147 + dahdi_transmit(&hfccard->span);
1149 + if (card->regs.fifo_en & hfc_FIFOEN_B1TX)
1150 + hfc_dahdi_transmit(&card->chans[B1].tx);
1151 + if (card->regs.fifo_en & hfc_FIFOEN_B2TX)
1152 + hfc_dahdi_transmit(&card->chans[B2].tx);
1155 + * dahdi hdlc frame tx
1158 + if (atomic_read(&hfccard->hdlc_pending)) {
1159 + hfc_check_l1_up(card);
1160 + res = dahdi_hdlc_getbuf(hfccard->sigchan, buf, &size);
1162 + hfccard->sigactive = 1;
1163 + memcpy(card->chans[D].tx.ugly_framebuf +
1164 + card->chans[D].tx.ugly_framebuf_size,
1166 + card->chans[D].tx.ugly_framebuf_size += size;
1168 + hfc_fifo_put_frame(&card->chans[D].tx,
1169 + card->chans[D].tx.ugly_framebuf,
1170 + card->chans[D].tx.ugly_framebuf_size);
1171 + ++hfccard->frames_out;
1172 + hfccard->sigactive = 0;
1173 + card->chans[D].tx.ugly_framebuf_size
1175 + atomic_dec(&hfccard->hdlc_pending);
1180 + * dahdi hdlc frame tx done
1183 + if (card->regs.fifo_en & hfc_FIFOEN_B1RX)
1184 + hfc_dahdi_receive(&card->chans[B1].rx);
1186 + memset(&card->chans[B1].rx.dahdi_buffer, 0x7f,
1187 + sizeof(card->chans[B1].rx.dahdi_buffer));
1189 + if (card->regs.fifo_en & hfc_FIFOEN_B2RX)
1190 + hfc_dahdi_receive(&card->chans[B2].rx);
1192 + memset(&card->chans[B2].rx.dahdi_buffer, 0x7f,
1193 + sizeof(card->chans[B1].rx.dahdi_buffer));
1196 + * Echo cancellation
1198 + dahdi_ec_chunk(&hfccard->chans[DAHDI_B1],
1199 + card->chans[B1].rx.dahdi_buffer,
1200 + card->chans[B1].tx.dahdi_buffer);
1201 + dahdi_ec_chunk(&hfccard->chans[DAHDI_B2],
1202 + card->chans[B2].rx.dahdi_buffer,
1203 + card->chans[B2].tx.dahdi_buffer);
1206 + * dahdi hdlc frame rx
1208 + if (hfc_fifo_has_frames(&card->chans[D].rx))
1209 + hfc_frame_arrived(&card->chans[D]);
1211 + if (card->chans[D].rx.ugly_framebuf_size) {
1212 + frame_left = card->chans[D].rx.ugly_framebuf_size -
1213 + card->chans[D].rx.ugly_framebuf_off ;
1214 + if (frame_left > hfc_HDLC_BUF_LEN) {
1215 + dahdi_hdlc_putbuf(hfccard->sigchan,
1216 + card->chans[D].rx.ugly_framebuf +
1217 + card->chans[D].rx.ugly_framebuf_off,
1218 + hfc_HDLC_BUF_LEN);
1219 + card->chans[D].rx.ugly_framebuf_off +=
1222 + dahdi_hdlc_putbuf(hfccard->sigchan,
1223 + card->chans[D].rx.ugly_framebuf +
1224 + card->chans[D].rx.ugly_framebuf_off,
1226 + dahdi_hdlc_finish(hfccard->sigchan);
1227 + card->chans[D].rx.ugly_framebuf_size = 0;
1228 + card->chans[D].rx.ugly_framebuf_off = 0;
1232 + * dahdi hdlc frame rx done
1235 + if (hfccard->span.flags & DAHDI_FLAG_RUNNING)
1236 + dahdi_receive(&hfccard->span);
1240 +static void hfc_frame_arrived(struct hfc_chan_duplex *chan)
1242 + struct hfc_card *card = chan->card;
1243 + int antiloop = 16;
1244 + struct sk_buff *skb;
1246 + while (hfc_fifo_has_frames(&chan->rx) && --antiloop) {
1247 + int frame_size = hfc_fifo_get_frame_size(&chan->rx);
1249 + if (frame_size < 3) {
1251 + if (debug_level >= 2)
1252 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1255 + "invalid frame received, "
1256 + "just %d bytes\n",
1262 + hfc_fifo_drop_frame(&chan->rx);
1266 + } else if (frame_size == 3) {
1268 + if (debug_level >= 2)
1269 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1272 + "empty frame received\n",
1277 + hfc_fifo_drop_frame(&chan->rx);
1283 + if (chan->open_by_dahdi &&
1284 + card->chans[D].rx.ugly_framebuf_size) {
1287 + * We have to wait for Dahdi to transmit the
1288 + * frame... wait for next time
1294 + skb = dev_alloc_skb(frame_size - 3);
1297 + printk(KERN_ERR hfc_DRIVER_PREFIX
1300 + "cannot allocate skb: frame dropped\n",
1304 + hfc_fifo_drop_frame(&chan->rx);
1312 + * HFC does the checksum
1314 +#ifndef CHECKSUM_HW
1315 + skb->ip_summed = CHECKSUM_COMPLETE;
1317 + skb->ip_summed = CHECKSUM_HW;
1320 + if (chan->open_by_dahdi) {
1321 + card->chans[D].rx.ugly_framebuf_size = frame_size - 1;
1323 + if (hfc_fifo_get_frame(&card->chans[D].rx,
1324 + card->chans[D].rx.ugly_framebuf,
1325 + frame_size - 1) == -1) {
1326 + dev_kfree_skb(skb);
1330 + memcpy(skb_put(skb, frame_size - 3),
1331 + card->chans[D].rx.ugly_framebuf,
1334 + if (hfc_fifo_get_frame(&chan->rx,
1335 + skb_put(skb, frame_size - 3),
1336 + frame_size - 3) == -1) {
1337 + dev_kfree_skb(skb);
1344 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1346 + "Infinite loop detected\n",
1350 +/******************************************
1351 + * Module initialization and cleanup
1352 + ******************************************/
1354 +static int __devinit hfc_probe(struct pci_dev *pci_dev,
1355 + const struct pci_device_id *ent)
1357 + static int cardnum;
1361 + struct hfc_card *card = NULL;
1362 + struct dahdi_hfc *dahdi_hfcs = NULL;
1363 + card = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
1365 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1366 + "unable to kmalloc!\n");
1368 + goto err_alloc_hfccard;
1371 + memset(card, 0x00, sizeof(struct hfc_card));
1372 + card->cardnum = cardnum;
1373 + card->pcidev = pci_dev;
1374 + spin_lock_init(&card->lock);
1376 + pci_set_drvdata(pci_dev, card);
1378 + err = pci_enable_device(pci_dev);
1380 + goto err_pci_enable_device;
1382 + err = pci_set_dma_mask(pci_dev, PCI_DMA_32BIT);
1384 + printk(KERN_ERR hfc_DRIVER_PREFIX
1386 + "No suitable DMA configuration available.\n",
1388 + goto err_pci_set_dma_mask;
1391 + pci_write_config_word(pci_dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
1392 + err = pci_request_regions(pci_dev, hfc_DRIVER_NAME);
1394 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1396 + "cannot request I/O memory region\n",
1398 + goto err_pci_request_regions;
1401 + pci_set_master(pci_dev);
1403 + if (!pci_dev->irq) {
1404 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1412 + card->io_bus_mem = pci_resource_start(pci_dev, 1);
1413 + if (!card->io_bus_mem) {
1414 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1419 + goto err_noiobase;
1422 + card->io_mem = ioremap(card->io_bus_mem, hfc_PCI_MEM_SIZE);
1423 + if (!(card->io_mem)) {
1424 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1426 + "cannot ioremap I/O memory\n",
1433 + * pci_alloc_consistent guarantees alignment
1434 + * (Documentation/DMA-mapping.txt)
1436 + card->fifo_mem = pci_alloc_consistent(pci_dev,
1437 + hfc_FIFO_SIZE, &card->fifo_bus_mem);
1438 + if (!card->fifo_mem) {
1439 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1441 + "unable to allocate FIFO DMA memory!\n",
1444 + goto err_alloc_fifo;
1447 + memset(card->fifo_mem, 0x00, hfc_FIFO_SIZE);
1449 + card->fifos = card->fifo_mem;
1451 + pci_write_config_dword(card->pcidev, hfc_PCI_MWBA, card->fifo_bus_mem);
1453 + err = request_irq(card->pcidev->irq, &hfc_interrupt,
1455 +#if (KERNEL_VERSION(2, 6, 23) < LINUX_VERSION_CODE)
1456 + IRQF_SHARED, hfc_DRIVER_NAME, card);
1458 + SA_SHIRQ, hfc_DRIVER_NAME, card);
1462 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1464 + "unable to register irq\n",
1466 + goto err_request_irq;
1469 + card->nt_mode = FALSE;
1471 + if (modes & (1 << card->cardnum))
1472 + card->nt_mode = TRUE;
1474 + for (i = 0; i < nt_modes_count; i++) {
1475 + if (nt_modes[i] == card->cardnum)
1476 + card->nt_mode = TRUE;
1482 + card->chans[D].card = card;
1483 + card->chans[D].name = "D";
1484 + card->chans[D].status = free;
1485 + card->chans[D].number = D;
1486 + spin_lock_init(&card->chans[D].lock);
1488 + card->chans[D].rx.chan = &card->chans[D];
1489 + card->chans[D].rx.fifo_base = card->fifos + 0x4000;
1490 + card->chans[D].rx.z_base = card->fifos + 0x4000;
1491 + card->chans[D].rx.z1_base = card->fifos + 0x6080;
1492 + card->chans[D].rx.z2_base = card->fifos + 0x6082;
1493 + card->chans[D].rx.z_min = 0x0000;
1494 + card->chans[D].rx.z_max = 0x01FF;
1495 + card->chans[D].rx.f_min = 0x10;
1496 + card->chans[D].rx.f_max = 0x1F;
1497 + card->chans[D].rx.f1 = card->fifos + 0x60a0;
1498 + card->chans[D].rx.f2 = card->fifos + 0x60a1;
1499 + card->chans[D].rx.fifo_size = card->chans[D].rx.z_max
1500 + - card->chans[D].rx.z_min + 1;
1501 + card->chans[D].rx.f_num = card->chans[D].rx.f_max
1502 + - card->chans[D].rx.f_min + 1;
1504 + card->chans[D].tx.chan = &card->chans[D];
1505 + card->chans[D].tx.fifo_base = card->fifos + 0x0000;
1506 + card->chans[D].tx.z_base = card->fifos + 0x0000;
1507 + card->chans[D].tx.z1_base = card->fifos + 0x2080;
1508 + card->chans[D].tx.z2_base = card->fifos + 0x2082;
1509 + card->chans[D].tx.z_min = 0x0000;
1510 + card->chans[D].tx.z_max = 0x01FF;
1511 + card->chans[D].tx.f_min = 0x10;
1512 + card->chans[D].tx.f_max = 0x1F;
1513 + card->chans[D].tx.f1 = card->fifos + 0x20a0;
1514 + card->chans[D].tx.f2 = card->fifos + 0x20a1;
1515 + card->chans[D].tx.fifo_size = card->chans[D].tx.z_max -
1516 + card->chans[D].tx.z_min + 1;
1517 + card->chans[D].tx.f_num = card->chans[D].tx.f_max -
1518 + card->chans[D].tx.f_min + 1;
1523 + card->chans[B1].card = card;
1524 + card->chans[B1].name = "B1";
1525 + card->chans[B1].status = free;
1526 + card->chans[B1].number = B1;
1527 + card->chans[B1].protocol = 0;
1528 + spin_lock_init(&card->chans[B1].lock);
1530 + card->chans[B1].rx.chan = &card->chans[B1];
1531 + card->chans[B1].rx.fifo_base = card->fifos + 0x4200;
1532 + card->chans[B1].rx.z_base = card->fifos + 0x4000;
1533 + card->chans[B1].rx.z1_base = card->fifos + 0x6000;
1534 + card->chans[B1].rx.z2_base = card->fifos + 0x6002;
1535 + card->chans[B1].rx.z_min = 0x0200;
1536 + card->chans[B1].rx.z_max = 0x1FFF;
1537 + card->chans[B1].rx.f_min = 0x00;
1538 + card->chans[B1].rx.f_max = 0x1F;
1539 + card->chans[B1].rx.f1 = card->fifos + 0x6080;
1540 + card->chans[B1].rx.f2 = card->fifos + 0x6081;
1541 + card->chans[B1].rx.fifo_size = card->chans[B1].rx.z_max -
1542 + card->chans[B1].rx.z_min + 1;
1543 + card->chans[B1].rx.f_num = card->chans[B1].rx.f_max -
1544 + card->chans[B1].rx.f_min + 1;
1546 + card->chans[B1].tx.chan = &card->chans[B1];
1547 + card->chans[B1].tx.fifo_base = card->fifos + 0x0200;
1548 + card->chans[B1].tx.z_base = card->fifos + 0x0000;
1549 + card->chans[B1].tx.z1_base = card->fifos + 0x2000;
1550 + card->chans[B1].tx.z2_base = card->fifos + 0x2002;
1551 + card->chans[B1].tx.z_min = 0x0200;
1552 + card->chans[B1].tx.z_max = 0x1FFF;
1553 + card->chans[B1].tx.f_min = 0x00;
1554 + card->chans[B1].tx.f_max = 0x1F;
1555 + card->chans[B1].tx.f1 = card->fifos + 0x2080;
1556 + card->chans[B1].tx.f2 = card->fifos + 0x2081;
1557 + card->chans[B1].tx.fifo_size = card->chans[B1].tx.z_max -
1558 + card->chans[B1].tx.z_min + 1;
1559 + card->chans[B1].tx.f_num = card->chans[B1].tx.f_max -
1560 + card->chans[B1].tx.f_min + 1;
1565 + card->chans[B2].card = card;
1566 + card->chans[B2].name = "B2";
1567 + card->chans[B2].status = free;
1568 + card->chans[B2].number = B2;
1569 + card->chans[B2].protocol = 0;
1570 + spin_lock_init(&card->chans[B2].lock);
1572 + card->chans[B2].rx.chan = &card->chans[B2];
1573 + card->chans[B2].rx.fifo_base = card->fifos + 0x6200,
1574 + card->chans[B2].rx.z_base = card->fifos + 0x6000;
1575 + card->chans[B2].rx.z1_base = card->fifos + 0x6100;
1576 + card->chans[B2].rx.z2_base = card->fifos + 0x6102;
1577 + card->chans[B2].rx.z_min = 0x0200;
1578 + card->chans[B2].rx.z_max = 0x1FFF;
1579 + card->chans[B2].rx.f_min = 0x00;
1580 + card->chans[B2].rx.f_max = 0x1F;
1581 + card->chans[B2].rx.f1 = card->fifos + 0x6180;
1582 + card->chans[B2].rx.f2 = card->fifos + 0x6181;
1583 + card->chans[B2].rx.fifo_size = card->chans[B2].rx.z_max -
1584 + card->chans[B2].rx.z_min + 1;
1585 + card->chans[B2].rx.f_num = card->chans[B2].rx.f_max -
1586 + card->chans[B2].rx.f_min + 1;
1588 + card->chans[B2].tx.chan = &card->chans[B2];
1589 + card->chans[B2].tx.fifo_base = card->fifos + 0x2200;
1590 + card->chans[B2].tx.z_base = card->fifos + 0x2000;
1591 + card->chans[B2].tx.z1_base = card->fifos + 0x2100;
1592 + card->chans[B2].tx.z2_base = card->fifos + 0x2102;
1593 + card->chans[B2].tx.z_min = 0x0200;
1594 + card->chans[B2].tx.z_max = 0x1FFF;
1595 + card->chans[B2].tx.f_min = 0x00;
1596 + card->chans[B2].tx.f_max = 0x1F;
1597 + card->chans[B2].tx.f1 = card->fifos + 0x2180;
1598 + card->chans[B2].tx.f2 = card->fifos + 0x2181;
1599 + card->chans[B2].tx.fifo_size = card->chans[B2].tx.z_max -
1600 + card->chans[B2].tx.z_min + 1;
1601 + card->chans[B2].tx.f_num = card->chans[B2].tx.f_max -
1602 + card->chans[B2].tx.f_min + 1;
1608 + dahdi_hfcs = kmalloc(sizeof(struct dahdi_hfc), GFP_KERNEL);
1609 + if (!dahdi_hfcs) {
1610 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1611 + "unable to kmalloc!\n");
1612 + goto err_request_irq;
1614 + memset(dahdi_hfcs, 0x0, sizeof(struct dahdi_hfc));
1616 + dahdi_hfcs->card = card;
1617 + hfc_dahdi_initialize(dahdi_hfcs);
1618 + card->dahdi_dev = dahdi_hfcs;
1620 + snprintf(card->proc_dir_name,
1621 + sizeof(card->proc_dir_name),
1622 + "%d", card->cardnum);
1623 + card->proc_dir = proc_mkdir(card->proc_dir_name, hfc_proc_dahdi_hfcs_dir);
1624 + SET_PROC_DIRENTRY_OWNER(card->proc_dir);
1626 + hfc_resetCard(card);
1628 + printk(KERN_INFO hfc_DRIVER_PREFIX
1629 + "card %d configured for %s mode at mem %#lx (0x%p) IRQ %u\n",
1631 + card->nt_mode ? "NT" : "TE",
1634 + card->pcidev->irq);
1641 + pci_free_consistent(pci_dev, hfc_FIFO_SIZE,
1642 + card->fifo_mem, card->fifo_bus_mem);
1644 + iounmap(card->io_mem);
1648 + pci_release_regions(pci_dev);
1649 +err_pci_request_regions:
1650 +err_pci_set_dma_mask:
1651 +err_pci_enable_device:
1657 +static void __devexit hfc_remove(struct pci_dev *pci_dev)
1659 + struct hfc_card *card = pci_get_drvdata(pci_dev);
1662 + printk(KERN_INFO hfc_DRIVER_PREFIX
1664 + "shutting down card at %p.\n",
1672 + hfc_softreset(card);
1674 + dahdi_unregister_device(card->dahdi_dev->ddev);
1678 + * disable memio and bustmaster
1680 + pci_write_config_word(pci_dev, PCI_COMMAND, 0);
1683 +BUG: these proc entries just cause Call traces, so removed.
1684 + remove_proc_entry("bufs", card->proc_dir);
1685 + remove_proc_entry("fifos", card->proc_dir);
1686 + remove_proc_entry("info", card->proc_dir);
1688 + remove_proc_entry(card->proc_dir_name, hfc_proc_dahdi_hfcs_dir);
1690 + free_irq(pci_dev->irq, card);
1692 + pci_free_consistent(pci_dev, hfc_FIFO_SIZE,
1693 + card->fifo_mem, card->fifo_bus_mem);
1695 + iounmap(card->io_mem);
1697 + pci_release_regions(pci_dev);
1699 + pci_disable_device(pci_dev);
1704 +/******************************************
1706 + ******************************************/
1708 +static int __init hfc_init_module(void)
1712 + printk(KERN_INFO hfc_DRIVER_PREFIX
1713 + hfc_DRIVER_STRING " loading\n");
1715 +printk(KERN_INFO hfc_DRIVER_PREFIX "Check /var/log/kern-debug.log for debugging output level %d.", debug_level);
1716 +printk(KERN_DEBUG hfc_DRIVER_PREFIX "base.c is debugging.");
1719 +#if (KERNEL_VERSION(2, 6, 26) <= LINUX_VERSION_CODE)
1720 + hfc_proc_dahdi_hfcs_dir = proc_mkdir(hfc_DRIVER_NAME, NULL);
1722 + hfc_proc_dahdi_hfcs_dir = proc_mkdir(hfc_DRIVER_NAME, proc_root_driver);
1725 + ret = dahdi_pci_module(&hfc_driver);
1729 +module_init(hfc_init_module);
1731 +static void __exit hfc_module_exit(void)
1733 + pci_unregister_driver(&hfc_driver);
1735 +#if (KERNEL_VERSION(2, 6, 26) <= LINUX_VERSION_CODE)
1736 + remove_proc_entry(hfc_DRIVER_NAME, NULL);
1738 + remove_proc_entry(hfc_DRIVER_NAME, proc_root_driver);
1741 + printk(KERN_INFO hfc_DRIVER_PREFIX
1742 + hfc_DRIVER_STRING " unloaded\n");
1745 +module_exit(hfc_module_exit);
1749 +MODULE_DESCRIPTION(hfc_DRIVER_DESCR);
1750 +MODULE_AUTHOR("Jens Wilke <jw_vzaphfc@headissue.com>, "
1751 + "Daniele (Vihai) Orlandi <daniele@orlandi.com>, "
1752 + "Jose A. Deniz <odicha@hotmail.com>");
1753 +MODULE_ALIAS("dahdi_hfcs");
1754 +#ifdef MODULE_LICENSE
1755 +MODULE_LICENSE("GPL");
1759 +module_param(modes, int, 0444);
1761 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
1762 +module_param_array(nt_modes, int, &nt_modes_count, 0444);
1764 +module_param_array(nt_modes, int, nt_modes_count, 0444);
1767 +module_param(force_l1_up, int, 0444);
1769 +module_param(debug_level, int, 0444);
1772 +MODULE_PARM_DESC(modes, "[Deprecated] bit-mask to configure NT mode");
1773 +MODULE_PARM_DESC(nt_modes,
1774 + "Comma-separated list of card IDs to configure in NT mode");
1775 +MODULE_PARM_DESC(force_l1_up, "Don't allow L1 to go down");
1777 +MODULE_PARM_DESC(debug_level, "Debug verbosity level");
1779 Index: dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/dahdi_hfcs.h
1780 ===================================================================
1782 +++ dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/dahdi_hfcs.h
1785 + * dahdi_hfcs.h - Dahdi driver for HFC-S PCI A based ISDN BRI cards
1787 + * Dahdi port by Jose A. Deniz <odicha@hotmail.com>
1789 + * Copyright (C) 2009 Jose A. Deniz
1790 + * Copyright (C) 2006 headissue GmbH; Jens Wilke
1791 + * Copyright (C) 2004 Daniele Orlandi
1792 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
1794 + * Jens Wilke <jw_vzaphfc@headissue.com>
1796 + * Orginal author of this code is
1797 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
1799 + * Major rewrite of the driver made by
1800 + * Klaus-Peter Junghanns <kpj@junghanns.net>
1802 + * This program is free software and may be modified and
1803 + * distributed under the terms of the GNU Public License.
1807 +#ifndef _HFC_ZAPHFC_H
1808 +#define _HFC_ZAPHFC_H
1810 +#include <asm/io.h>
1812 +#define hfc_DRIVER_NAME "dahdi_hfcs"
1813 +#define hfc_DRIVER_PREFIX hfc_DRIVER_NAME ": "
1814 +#define hfc_DRIVER_DESCR "HFC-S PCI A ISDN"
1815 +#define hfc_DRIVER_VERSION "1.42"
1816 +#define hfc_DRIVER_STRING hfc_DRIVER_DESCR " (V" hfc_DRIVER_VERSION ")"
1818 +#define hfc_MAX_BOARDS 32
1820 +#ifndef PCI_DMA_32BIT
1821 +#define PCI_DMA_32BIT 0x00000000ffffffffULL
1824 +#ifndef PCI_VENDOR_ID_SITECOM
1825 +#define PCI_VENDOR_ID_SITECOM 0x182D
1828 +#ifndef PCI_DEVICE_ID_SITECOM_3069
1829 +#define PCI_DEVICE_ID_SITECOM_3069 0x3069
1832 +#define hfc_RESET_DELAY 20
1834 +#define hfc_CLKDEL_TE 0x0f /* CLKDEL in TE mode */
1835 +#define hfc_CLKDEL_NT 0x6c /* CLKDEL in NT mode */
1837 +/* PCI memory mapped I/O */
1839 +#define hfc_PCI_MEM_SIZE 0x0100
1840 +#define hfc_PCI_MWBA 0x80
1842 +/* GCI/IOM bus monitor registers */
1844 +#define hfc_C_I 0x08
1845 +#define hfc_TRxR 0x0C
1846 +#define hfc_MON1_D 0x28
1847 +#define hfc_MON2_D 0x2C
1850 +/* GCI/IOM bus timeslot registers */
1852 +#define hfc_B1_SSL 0x80
1853 +#define hfc_B2_SSL 0x84
1854 +#define hfc_AUX1_SSL 0x88
1855 +#define hfc_AUX2_SSL 0x8C
1856 +#define hfc_B1_RSL 0x90
1857 +#define hfc_B2_RSL 0x94
1858 +#define hfc_AUX1_RSL 0x98
1859 +#define hfc_AUX2_RSL 0x9C
1861 +/* GCI/IOM bus data registers */
1863 +#define hfc_B1_D 0xA0
1864 +#define hfc_B2_D 0xA4
1865 +#define hfc_AUX1_D 0xA8
1866 +#define hfc_AUX2_D 0xAC
1868 +/* GCI/IOM bus configuration registers */
1870 +#define hfc_MST_EMOD 0xB4
1871 +#define hfc_MST_MODE 0xB8
1872 +#define hfc_CONNECT 0xBC
1875 +/* Interrupt and status registers */
1877 +#define hfc_FIFO_EN 0x44
1878 +#define hfc_TRM 0x48
1879 +#define hfc_B_MODE 0x4C
1880 +#define hfc_CHIP_ID 0x58
1881 +#define hfc_CIRM 0x60
1882 +#define hfc_CTMT 0x64
1883 +#define hfc_INT_M1 0x68
1884 +#define hfc_INT_M2 0x6C
1885 +#define hfc_INT_S1 0x78
1886 +#define hfc_INT_S2 0x7C
1887 +#define hfc_STATUS 0x70
1889 +/* S/T section registers */
1891 +#define hfc_STATES 0xC0
1892 +#define hfc_SCTRL 0xC4
1893 +#define hfc_SCTRL_E 0xC8
1894 +#define hfc_SCTRL_R 0xCC
1895 +#define hfc_SQ 0xD0
1896 +#define hfc_CLKDEL 0xDC
1897 +#define hfc_B1_REC 0xF0
1898 +#define hfc_B1_SEND 0xF0
1899 +#define hfc_B2_REC 0xF4
1900 +#define hfc_B2_SEND 0xF4
1901 +#define hfc_D_REC 0xF8
1902 +#define hfc_D_SEND 0xF8
1903 +#define hfc_E_REC 0xFC
1905 +/* Bits and values in various HFC PCI registers */
1907 +/* bits in status register (READ) */
1908 +#define hfc_STATUS_PCI_PROC 0x02
1909 +#define hfc_STATUS_NBUSY 0x04
1910 +#define hfc_STATUS_TIMER_ELAP 0x10
1911 +#define hfc_STATUS_STATINT 0x20
1912 +#define hfc_STATUS_FRAMEINT 0x40
1913 +#define hfc_STATUS_ANYINT 0x80
1915 +/* bits in CTMT (Write) */
1916 +#define hfc_CTMT_TRANSB1 0x01
1917 +#define hfc_CTMT_TRANSB2 0x02
1918 +#define hfc_CTMT_TIMER_CLEAR 0x80
1919 +#define hfc_CTMT_TIMER_MASK 0x1C
1920 +#define hfc_CTMT_TIMER_3_125 (0x01 << 2)
1921 +#define hfc_CTMT_TIMER_6_25 (0x02 << 2)
1922 +#define hfc_CTMT_TIMER_12_5 (0x03 << 2)
1923 +#define hfc_CTMT_TIMER_25 (0x04 << 2)
1924 +#define hfc_CTMT_TIMER_50 (0x05 << 2)
1925 +#define hfc_CTMT_TIMER_400 (0x06 << 2)
1926 +#define hfc_CTMT_TIMER_800 (0x07 << 2)
1927 +#define hfc_CTMT_AUTO_TIMER 0x20
1929 +/* bits in CIRM (Write) */
1930 +#define hfc_CIRM_AUX_MSK 0x07
1931 +#define hfc_CIRM_RESET 0x08
1932 +#define hfc_CIRM_B1_REV 0x40
1933 +#define hfc_CIRM_B2_REV 0x80
1935 +/* bits in INT_M1 and INT_S1 */
1936 +#define hfc_INTS_B1TRANS 0x01
1937 +#define hfc_INTS_B2TRANS 0x02
1938 +#define hfc_INTS_DTRANS 0x04
1939 +#define hfc_INTS_B1REC 0x08
1940 +#define hfc_INTS_B2REC 0x10
1941 +#define hfc_INTS_DREC 0x20
1942 +#define hfc_INTS_L1STATE 0x40
1943 +#define hfc_INTS_TIMER 0x80
1945 +/* bits in INT_M2 */
1946 +#define hfc_M2_PROC_TRANS 0x01
1947 +#define hfc_M2_GCI_I_CHG 0x02
1948 +#define hfc_M2_GCI_MON_REC 0x04
1949 +#define hfc_M2_IRQ_ENABLE 0x08
1950 +#define hfc_M2_PMESEL 0x80
1952 +/* bits in STATES */
1953 +#define hfc_STATES_STATE_MASK 0x0F
1954 +#define hfc_STATES_LOAD_STATE 0x10
1955 +#define hfc_STATES_ACTIVATE 0x20
1956 +#define hfc_STATES_DO_ACTION 0x40
1957 +#define hfc_STATES_NT_G2_G3 0x80
1959 +/* bits in HFCD_MST_MODE */
1960 +#define hfc_MST_MODE_MASTER 0x01
1961 +#define hfc_MST_MODE_SLAVE 0x00
1962 +/* remaining bits are for codecs control */
1964 +/* bits in HFCD_SCTRL */
1965 +#define hfc_SCTRL_B1_ENA 0x01
1966 +#define hfc_SCTRL_B2_ENA 0x02
1967 +#define hfc_SCTRL_MODE_TE 0x00
1968 +#define hfc_SCTRL_MODE_NT 0x04
1969 +#define hfc_SCTRL_LOW_PRIO 0x08
1970 +#define hfc_SCTRL_SQ_ENA 0x10
1971 +#define hfc_SCTRL_TEST 0x20
1972 +#define hfc_SCTRL_NONE_CAP 0x40
1973 +#define hfc_SCTRL_PWR_DOWN 0x80
1975 +/* bits in SCTRL_E */
1976 +#define hfc_SCTRL_E_AUTO_AWAKE 0x01
1977 +#define hfc_SCTRL_E_DBIT_1 0x04
1978 +#define hfc_SCTRL_E_IGNORE_COL 0x08
1979 +#define hfc_SCTRL_E_CHG_B1_B2 0x80
1981 +/* bits in SCTRL_R */
1982 +#define hfc_SCTRL_R_B1_ENA 0x01
1983 +#define hfc_SCTRL_R_B2_ENA 0x02
1985 +/* bits in FIFO_EN register */
1986 +#define hfc_FIFOEN_B1TX 0x01
1987 +#define hfc_FIFOEN_B1RX 0x02
1988 +#define hfc_FIFOEN_B2TX 0x04
1989 +#define hfc_FIFOEN_B2RX 0x08
1990 +#define hfc_FIFOEN_DTX 0x10
1991 +#define hfc_FIFOEN_DRX 0x20
1993 +#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
1994 +#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
1995 +#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
1997 +/* bits in the CONNECT register */
1998 +#define hfc_CONNECT_B1_HFC_from_ST 0x00
1999 +#define hfc_CONNECT_B1_HFC_from_GCI 0x01
2000 +#define hfc_CONNECT_B1_ST_from_HFC 0x00
2001 +#define hfc_CONNECT_B1_ST_from_GCI 0x02
2002 +#define hfc_CONNECT_B1_GCI_from_HFC 0x00
2003 +#define hfc_CONNECT_B1_GCI_from_ST 0x04
2005 +#define hfc_CONNECT_B2_HFC_from_ST 0x00
2006 +#define hfc_CONNECT_B2_HFC_from_GCI 0x08
2007 +#define hfc_CONNECT_B2_ST_from_HFC 0x00
2008 +#define hfc_CONNECT_B2_ST_from_GCI 0x10
2009 +#define hfc_CONNECT_B2_GCI_from_HFC 0x00
2010 +#define hfc_CONNECT_B2_GCI_from_ST 0x20
2012 +/* bits in the TRM register */
2013 +#define hfc_TRM_TRANS_INT_00 0x00
2014 +#define hfc_TRM_TRANS_INT_01 0x01
2015 +#define hfc_TRM_TRANS_INT_10 0x02
2016 +#define hfc_TRM_TRANS_INT_11 0x04
2017 +#define hfc_TRM_ECHO 0x20
2018 +#define hfc_TRM_B1_PLUS_B2 0x40
2019 +#define hfc_TRM_IOM_TEST_LOOP 0x80
2021 +/* bits in the __SSL and __RSL registers */
2022 +#define hfc_SRSL_STIO 0x40
2023 +#define hfc_SRSL_ENABLE 0x80
2024 +#define hfc_SRCL_SLOT_MASK 0x1f
2026 +/* FIFO memory definitions */
2028 +#define hfc_FIFO_SIZE 0x8000
2030 +#define hfc_UGLY_FRAMEBUF 0x2000
2032 +#define hfc_TX_FIFO_PRELOAD (DAHDI_CHUNKSIZE + 2)
2033 +#define hfc_RX_FIFO_PRELOAD 4
2036 +#define hfc_HDLC_BUF_LEN 32
2037 +/* arbitrary, just the max # of byts we will send to DAHDI per call */
2040 +/* NOTE: FIFO pointers are not declared volatile because accesses to the
2041 + * FIFOs are inherently safe.
2045 +extern int debug_level;
2050 +struct hfc_chan_simplex {
2051 + struct hfc_chan_duplex *chan;
2053 + u8 dahdi_buffer[DAHDI_CHUNKSIZE];
2055 + u8 ugly_framebuf[hfc_UGLY_FRAMEBUF];
2056 + int ugly_framebuf_size;
2057 + u16 ugly_framebuf_off;
2059 + void *z1_base, *z2_base;
2071 + unsigned long long frames;
2072 + unsigned long long bytes;
2073 + unsigned long long fifo_full;
2074 + unsigned long long crc;
2075 + unsigned long long fifo_underrun;
2078 +enum hfc_chan_status {
2086 +struct hfc_chan_duplex {
2087 + struct hfc_card *card;
2092 + enum hfc_chan_status status;
2093 + int open_by_netdev;
2094 + int open_by_dahdi;
2096 + unsigned short protocol;
2100 + struct hfc_chan_simplex rx;
2101 + struct hfc_chan_simplex tx;
2105 +typedef struct hfc_card {
2107 + struct pci_dev *pcidev;
2108 + struct dahdi_hfc *dahdi_dev;
2109 + struct proc_dir_entry *proc_dir;
2110 + char proc_dir_name[32];
2112 + struct proc_dir_entry *proc_info;
2113 + struct proc_dir_entry *proc_fifos;
2114 + struct proc_dir_entry *proc_bufs;
2116 + unsigned long io_bus_mem;
2117 + void __iomem *io_mem;
2119 + dma_addr_t fifo_bus_mem;
2124 + int sync_loss_reported;
2128 + int fifo_suspended;
2129 + int ignore_first_timer_interrupt;
2144 + struct hfc_chan_duplex chans[3];
2153 + unsigned int iomem;
2156 + unsigned char *pci_io;
2157 + void *fifomem; /* start of the shared mem */
2159 + unsigned int pcibus;
2160 + unsigned int pcidevfn;
2164 + unsigned char cardno;
2165 + struct hfc_card *next;
2169 +typedef struct dahdi_hfc {
2170 + unsigned int usecount;
2171 + struct dahdi_device *ddev;
2172 + struct dahdi_span span;
2173 + struct dahdi_chan chans[3];
2174 + struct dahdi_chan *_chans[3];
2175 + struct hfc_card *card;
2177 + /* pointer to the signalling channel for this span */
2178 + struct dahdi_chan *sigchan;
2179 + /* nonzero means we're in the middle of sending an HDLC frame */
2181 + /* hdlc_hard_xmit() increments, hdlc_tx_frame() decrements */
2182 + atomic_t hdlc_pending;
2188 +static inline struct dahdi_hfc* dahdi_hfc_from_span(struct dahdi_span *span) {
2189 + return container_of(span, struct dahdi_hfc, span);
2192 +static inline u8 hfc_inb(struct hfc_card *card, int offset)
2194 + return readb(card->io_mem + offset);
2197 +static inline void hfc_outb(struct hfc_card *card, int offset, u8 value)
2199 + writeb(value, card->io_mem + offset);
2203 Index: dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/fifo.c
2204 ===================================================================
2206 +++ dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/fifo.c
2209 + * fifo.c - HFC FIFO management routines
2211 + * Copyright (C) 2006 headissue GmbH; Jens Wilke
2212 + * Copyright (C) 2004 Daniele Orlandi
2213 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
2215 + * Original author of this code is
2216 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
2218 + * This program is free software and may be modified and
2219 + * distributed under the terms of the GNU Public License.
2225 +extern int debug_level;
2228 +#include <linux/kernel.h>
2230 +#include <dahdi/kernel.h>
2234 +static void hfc_fifo_mem_read(struct hfc_chan_simplex *chan,
2236 + void *data, int size)
2238 + int bytes_to_boundary = chan->z_max - z_start + 1;
2239 + if (bytes_to_boundary >= size) {
2241 + chan->z_base + z_start,
2248 + chan->z_base + z_start,
2249 + bytes_to_boundary);
2251 + memcpy(data + bytes_to_boundary,
2253 + size - bytes_to_boundary);
2257 +static void hfc_fifo_mem_write(struct hfc_chan_simplex *chan,
2258 + void *data, int size)
2260 + int bytes_to_boundary = chan->z_max - *Z1_F1(chan) + 1;
2261 + if (bytes_to_boundary >= size) {
2262 + memcpy(chan->z_base + *Z1_F1(chan),
2270 + memcpy(chan->z_base + *Z1_F1(chan),
2272 + bytes_to_boundary);
2274 + memcpy(chan->fifo_base,
2275 + data + bytes_to_boundary,
2276 + size - bytes_to_boundary);
2280 +int hfc_fifo_get(struct hfc_chan_simplex *chan,
2281 + void *data, int size)
2283 + int available_bytes;
2286 + * Some useless statistic
2288 + chan->bytes += size;
2290 + available_bytes = hfc_fifo_used_rx(chan);
2292 + if (available_bytes < size && !chan->fifo_underrun++) {
2294 + * print the warning only once
2296 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2299 + "RX FIFO not enough (%d) bytes to receive!\n",
2300 + chan->chan->card->cardnum,
2306 + hfc_fifo_mem_read(chan, *Z2_F2(chan), data, size);
2307 + *Z2_F2(chan) = Z_inc(chan, *Z2_F2(chan), size);
2308 + return available_bytes - size;
2311 +void hfc_fifo_put(struct hfc_chan_simplex *chan,
2312 + void *data, int size)
2314 + struct hfc_card *card = chan->chan->card;
2315 + int used_bytes = hfc_fifo_used_tx(chan);
2316 + int free_bytes = hfc_fifo_free_tx(chan);
2318 + if (!used_bytes && !chan->fifo_underrun++) {
2320 + * print warning only once, to make timing not worse
2322 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2325 + "TX FIFO has become empty\n",
2327 + chan->chan->name);
2329 + if (free_bytes < size) {
2330 + printk(KERN_CRIT hfc_DRIVER_PREFIX
2333 + "TX FIFO full!\n",
2334 + chan->chan->card->cardnum,
2335 + chan->chan->name);
2336 + chan->fifo_full++;
2337 + hfc_clear_fifo_tx(chan);
2340 + hfc_fifo_mem_write(chan, data, size);
2341 + chan->bytes += size;
2342 + *Z1_F1(chan) = Z_inc(chan, *Z1_F1(chan), size);
2345 +int hfc_fifo_get_frame(struct hfc_chan_simplex *chan, void *data, int max_size)
2350 + if (*chan->f1 == *chan->f2) {
2352 + * nothing received, strange uh?
2354 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2357 + "get_frame called with no frame in FIFO.\n",
2358 + chan->chan->card->cardnum,
2359 + chan->chan->name);
2365 + * frame_size includes CRC+CRC+STAT
2367 + frame_size = hfc_fifo_get_frame_size(chan);
2370 + if (debug_level == 3) {
2371 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2375 + chan->chan->card->cardnum,
2378 + } else if (debug_level >= 4) {
2379 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2382 + "RX (f1=%02x, f2=%02x, z1=%04x, z2=%04x) len %2d: ",
2383 + chan->chan->card->cardnum,
2385 + *chan->f1, *chan->f2, *Z1_F2(chan), *Z2_F2(chan),
2389 + if (debug_level >= 3) {
2391 + for (i = 0; i < frame_size; i++) {
2392 + printk("%02x", hfc_fifo_u8(chan,
2393 + Z_inc(chan, *Z2_F2(chan), i)));
2400 + if (frame_size <= 0) {
2402 + if (debug_level >= 2) {
2403 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2406 + "invalid (empty) frame received.\n",
2407 + chan->chan->card->cardnum,
2408 + chan->chan->name);
2412 + hfc_fifo_drop_frame(chan);
2417 + * STAT is not really received
2419 + chan->bytes += frame_size - 1;
2422 + * Calculate beginning of the next frame
2424 + newz2 = Z_inc(chan, *Z2_F2(chan), frame_size);
2427 + * We cannot use hfc_fifo_get because of different semantic of
2428 + * "available bytes" and to avoid useless increment of Z2
2430 + hfc_fifo_mem_read(chan, *Z2_F2(chan), data,
2431 + frame_size < max_size ? frame_size : max_size);
2433 + if (hfc_fifo_u8(chan, Z_inc(chan, *Z2_F2(chan),
2434 + frame_size - 1)) != 0x00) {
2436 + * CRC not ok, frame broken, skipping
2439 + if (debug_level >= 2) {
2440 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2443 + "Received frame with wrong CRC\n",
2444 + chan->chan->card->cardnum,
2445 + chan->chan->name);
2451 + hfc_fifo_drop_frame(chan);
2457 + *chan->f2 = F_inc(chan, *chan->f2, 1);
2460 + * Set Z2 for the next frame we're going to receive
2462 + *Z2_F2(chan) = newz2;
2464 + return frame_size;
2467 +void hfc_fifo_drop_frame(struct hfc_chan_simplex *chan)
2469 + int available_bytes;
2472 + if (*chan->f1 == *chan->f2) {
2474 + * nothing received, strange eh?
2476 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2479 + "skip_frame called with no frame in FIFO.\n",
2480 + chan->chan->card->cardnum,
2481 + chan->chan->name);
2486 + available_bytes = hfc_fifo_used_rx(chan) + 1;
2489 + * Calculate beginning of the next frame
2491 + newz2 = Z_inc(chan, *Z2_F2(chan), available_bytes);
2493 + *chan->f2 = F_inc(chan, *chan->f2, 1);
2496 + * Set Z2 for the next frame we're going to receive
2498 + *Z2_F2(chan) = newz2;
2501 +void hfc_fifo_put_frame(struct hfc_chan_simplex *chan,
2502 + void *data, int size)
2505 + int available_frames;
2508 + if (debug_level == 3) {
2509 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2513 + chan->chan->card->cardnum,
2516 + } else if (debug_level >= 4) {
2517 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2520 + "TX (f1=%02x, f2=%02x, z1=%04x, z2=%04x) len %2d: ",
2521 + chan->chan->card->cardnum,
2523 + *chan->f1, *chan->f2, *Z1_F1(chan), *Z2_F1(chan),
2527 + if (debug_level >= 3) {
2529 + for (i = 0; i < size; i++)
2530 + printk("%02x", ((u8 *)data)[i]);
2536 + available_frames = hfc_fifo_free_frames(chan);
2538 + if (available_frames >= chan->f_num) {
2539 + printk(KERN_CRIT hfc_DRIVER_PREFIX
2542 + "TX FIFO total number of frames exceeded!\n",
2543 + chan->chan->card->cardnum,
2544 + chan->chan->name);
2546 + chan->fifo_full++;
2551 + hfc_fifo_put(chan, data, size);
2553 + newz1 = *Z1_F1(chan);
2555 + *chan->f1 = F_inc(chan, *chan->f1, 1);
2557 + *Z1_F1(chan) = newz1;
2562 +void hfc_clear_fifo_rx(struct hfc_chan_simplex *chan)
2564 + *chan->f2 = *chan->f1;
2565 + *Z2_F2(chan) = *Z1_F2(chan);
2568 +void hfc_clear_fifo_tx(struct hfc_chan_simplex *chan)
2570 + *chan->f1 = *chan->f2;
2571 + *Z1_F1(chan) = *Z2_F1(chan);
2573 + if (chan->chan->status == open_voice) {
2575 + * Make sure that at least hfc_TX_FIFO_PRELOAD bytes are
2576 + * present in the TX FIFOs
2577 + * Create hfc_TX_FIFO_PRELOAD bytes of empty data
2578 + * (0x7f is mute audio)
2580 + u8 empty_fifo[hfc_TX_FIFO_PRELOAD +
2581 + DAHDI_CHUNKSIZE + hfc_RX_FIFO_PRELOAD];
2582 + memset(empty_fifo, 0x7f, sizeof(empty_fifo));
2584 + hfc_fifo_put(chan, empty_fifo, sizeof(empty_fifo));
2588 Index: dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/fifo.h
2589 ===================================================================
2591 +++ dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/fifo.h
2594 + * fifo.h - Dahdi driver for HFC-S PCI A based ISDN BRI cards
2596 + * Copyright (C) 2004 Daniele Orlandi
2597 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
2599 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
2601 + * Major rewrite of the driver made by
2602 + * Klaus-Peter Junghanns <kpj@junghanns.net>
2604 + * This program is free software and may be modified and
2605 + * distributed under the terms of the GNU Public License.
2609 +#ifndef _HFC_FIFO_H
2610 +#define _HFC_FIFO_H
2612 +#include "dahdi_hfcs.h"
2614 +static inline u16 *Z1_F1(struct hfc_chan_simplex *chan)
2616 + return chan->z1_base + (*chan->f1 * 4);
2619 +static inline u16 *Z2_F1(struct hfc_chan_simplex *chan)
2621 + return chan->z2_base + (*chan->f1 * 4);
2624 +static inline u16 *Z1_F2(struct hfc_chan_simplex *chan)
2626 + return chan->z1_base + (*chan->f2 * 4);
2629 +static inline u16 *Z2_F2(struct hfc_chan_simplex *chan)
2631 + return chan->z2_base + (*chan->f2 * 4);
2634 +static inline u16 Z_inc(struct hfc_chan_simplex *chan, u16 z, u16 inc)
2637 + * declared as u32 in order to manage overflows
2639 + u32 newz = z + inc;
2640 + if (newz > chan->z_max)
2641 + newz -= chan->fifo_size;
2646 +static inline u8 F_inc(struct hfc_chan_simplex *chan, u8 f, u8 inc)
2649 + * declared as u16 in order to manage overflows
2651 + u16 newf = f + inc;
2652 + if (newf > chan->f_max)
2653 + newf -= chan->f_num;
2658 +static inline u16 hfc_fifo_used_rx(struct hfc_chan_simplex *chan)
2660 + return (*Z1_F2(chan) - *Z2_F2(chan) +
2661 + chan->fifo_size) % chan->fifo_size;
2664 +static inline u16 hfc_fifo_get_frame_size(struct hfc_chan_simplex *chan)
2667 + * This +1 is needed because in frame mode the available bytes are Z2-Z1+1
2668 + * while in transparent mode I wouldn't consider the byte pointed by Z2 to
2669 + * be available, otherwise, the FIFO would always contain one byte, even
2673 + return hfc_fifo_used_rx(chan) + 1;
2676 +static inline u8 hfc_fifo_u8(struct hfc_chan_simplex *chan, u16 z)
2678 + return *((u8 *)(chan->z_base + z));
2681 +static inline u16 hfc_fifo_used_tx(struct hfc_chan_simplex *chan)
2683 + return (*Z1_F1(chan) - *Z2_F1(chan) +
2684 + chan->fifo_size) % chan->fifo_size;
2687 +static inline u16 hfc_fifo_free_rx(struct hfc_chan_simplex *chan)
2689 + u16 free_bytes = *Z2_F1(chan) - *Z1_F1(chan);
2691 + if (free_bytes > 0)
2692 + return free_bytes;
2694 + return free_bytes + chan->fifo_size;
2697 +static inline u16 hfc_fifo_free_tx(struct hfc_chan_simplex *chan)
2699 + u16 free_bytes = *Z2_F1(chan) - *Z1_F1(chan);
2701 + if (free_bytes > 0)
2702 + return free_bytes;
2704 + return free_bytes + chan->fifo_size;
2707 +static inline int hfc_fifo_has_frames(struct hfc_chan_simplex *chan)
2709 + return *chan->f1 != *chan->f2;
2712 +static inline u8 hfc_fifo_used_frames(struct hfc_chan_simplex *chan)
2714 + return (*chan->f1 - *chan->f2 + chan->f_num) % chan->f_num;
2717 +static inline u8 hfc_fifo_free_frames(struct hfc_chan_simplex *chan)
2719 + return (*chan->f2 - *chan->f1 + chan->f_num) % chan->f_num;
2722 +int hfc_fifo_get(struct hfc_chan_simplex *chan, void *data, int size);
2723 +void hfc_fifo_put(struct hfc_chan_simplex *chan, void *data, int size);
2724 +void hfc_fifo_drop(struct hfc_chan_simplex *chan, int size);
2725 +int hfc_fifo_get_frame(struct hfc_chan_simplex *chan, void *data, int max_size);
2726 +void hfc_fifo_drop_frame(struct hfc_chan_simplex *chan);
2727 +void hfc_fifo_put_frame(struct hfc_chan_simplex *chan, void *data, int size);
2728 +void hfc_clear_fifo_rx(struct hfc_chan_simplex *chan);
2729 +void hfc_clear_fifo_tx(struct hfc_chan_simplex *chan);
2732 Index: dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/Kbuild
2733 ===================================================================
2735 +++ dahdi-linux-2.10.0.1/drivers/dahdi/hfcs/Kbuild
2737 +obj-m += dahdi_hfcs.o
2739 +EXTRA_CFLAGS := -I$(src)/.. -Wno-undef
2741 +dahdi_hfcs-objs := base.o fifo.o
2743 +$(obj)/base.o: $(src)/dahdi_hfcs.h
2744 +$(obj)/fifo.o: $(src)/fifo.h