]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/isdn/hardware/mISDN/hfcpci.c
mISDN: Use protocol to detect D-channel
[linux-2.6-omap-h63xx.git] / drivers / isdn / hardware / mISDN / hfcpci.c
index 9cf5edbb1a9b119db51d1b60494b3767886184d8..37c2e19c3b008801cc390d8d25076761ecd27303 100644 (file)
@@ -34,7 +34,6 @@
 
 static const char *hfcpci_revision = "2.0";
 
-#define MAX_CARDS      8
 static int HFC_cnt;
 static uint debug;
 
@@ -43,7 +42,7 @@ MODULE_LICENSE("GPL");
 module_param(debug, uint, 0);
 
 static LIST_HEAD(HFClist);
-DEFINE_RWLOCK(HFClock);
+static DEFINE_RWLOCK(HFClock);
 
 enum {
        HFC_CCD_2BD0,
@@ -88,7 +87,7 @@ struct hfcPCI_hw {
        unsigned char           bswapped;
        unsigned char           protocol;
        int                     nt_timer;
-       unsigned char           *pci_io; /* start of PCI IO memory */
+       unsigned char __iomem   *pci_io; /* start of PCI IO memory */
        dma_addr_t              dmahandle;
        void                    *fifos; /* FIFO memory */
        int                     last_bfifo_cnt[2];
@@ -153,7 +152,7 @@ release_io_hfcpci(struct hfc_pci *hc)
        pci_write_config_word(hc->pdev, PCI_COMMAND, 0);
        del_timer(&hc->hw.timer);
        pci_free_consistent(hc->pdev, 0x8000, hc->hw.fifos, hc->hw.dmahandle);
-       iounmap((void *)hc->hw.pci_io);
+       iounmap(hc->hw.pci_io);
 }
 
 /*
@@ -366,8 +365,7 @@ static void hfcpci_clear_fifo_tx(struct hfc_pci *hc, int fifo)
        bzt->f2 = MAX_B_FRAMES;
        bzt->f1 = bzt->f2;      /* init F pointers to remain constant */
        bzt->za[MAX_B_FRAMES].z1 = cpu_to_le16(B_FIFO_SIZE + B_SUB_VAL - 1);
-       bzt->za[MAX_B_FRAMES].z2 = cpu_to_le16(
-           le16_to_cpu(bzt->za[MAX_B_FRAMES].z1 - 1));
+       bzt->za[MAX_B_FRAMES].z2 = cpu_to_le16(B_FIFO_SIZE + B_SUB_VAL - 2);
        if (fifo_state)
                hc->hw.fifo_en |= fifo_state;
        Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
@@ -482,7 +480,7 @@ receive_dmsg(struct hfc_pci *hc)
                        df->f2 = ((df->f2 + 1) & MAX_D_FRAMES) |
                            (MAX_D_FRAMES + 1); /* next buffer */
                        df->za[df->f2 & D_FREG_MASK].z2 =
-                           cpu_to_le16((zp->z2 + rcnt) & (D_FIFO_SIZE - 1));
+                           cpu_to_le16((le16_to_cpu(zp->z2) + rcnt) & (D_FIFO_SIZE - 1));
                } else {
                        dch->rx_skb = mI_alloc_skb(rcnt - 3, GFP_ATOMIC);
                        if (!dch->rx_skb) {
@@ -523,10 +521,10 @@ receive_dmsg(struct hfc_pci *hc)
 /*
  * check for transparent receive data and read max one threshold size if avail
  */
-int
+static int
 hfcpci_empty_fifo_trans(struct bchannel *bch, struct bzfifo *bz, u_char *bdata)
 {
-       unsigned short  *z1r, *z2r;
+        __le16 *z1r, *z2r;
        int             new_z2, fcnt, maxlen;
        u_char          *ptr, *ptr1;
 
@@ -576,7 +574,7 @@ hfcpci_empty_fifo_trans(struct bchannel *bch, struct bzfifo *bz, u_char *bdata)
 /*
  * B-channel main receive routine
  */
-void
+static void
 main_rec_hfcpci(struct bchannel *bch)
 {
        struct hfc_pci  *hc = bch->hw;
@@ -724,7 +722,7 @@ hfcpci_fill_fifo(struct bchannel *bch)
        struct bzfifo   *bz;
        u_char          *bdata;
        u_char          new_f1, *src, *dst;
-       unsigned short  *z1t, *z2t;
+       __le16 *z1t, *z2t;
 
        if ((bch->debug & DEBUG_HW_BCHANNEL) && !(bch->debug & DEBUG_HW_BFIFO))
                printk(KERN_DEBUG "%s\n", __func__);
@@ -752,6 +750,36 @@ hfcpci_fill_fifo(struct bchannel *bch)
                            /* fcnt contains available bytes in fifo */
                fcnt = B_FIFO_SIZE - fcnt;
                    /* remaining bytes to send (bytes in fifo) */
+
+               /* "fill fifo if empty" feature */
+               if (test_bit(FLG_FILLEMPTY, &bch->Flags) && !fcnt) {
+                       /* printk(KERN_DEBUG "%s: buffer empty, so we have "
+                               "underrun\n", __func__); */
+                       /* fill buffer, to prevent future underrun */
+                       count = HFCPCI_FILLEMPTY;
+                       new_z1 = le16_to_cpu(*z1t) + count;
+                          /* new buffer Position */
+                       if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL))
+                               new_z1 -= B_FIFO_SIZE;  /* buffer wrap */
+                       dst = bdata + (le16_to_cpu(*z1t) - B_SUB_VAL);
+                       maxlen = (B_FIFO_SIZE + B_SUB_VAL) - le16_to_cpu(*z1t);
+                           /* end of fifo */
+                       if (bch->debug & DEBUG_HW_BFIFO)
+                               printk(KERN_DEBUG "hfcpci_FFt fillempty "
+                                   "fcnt(%d) maxl(%d) nz1(%x) dst(%p)\n",
+                                   fcnt, maxlen, new_z1, dst);
+                       fcnt += count;
+                       if (maxlen > count)
+                               maxlen = count;         /* limit size */
+                       memset(dst, 0x2a, maxlen);      /* first copy */
+                       count -= maxlen;                /* remaining bytes */
+                       if (count) {
+                               dst = bdata;            /* start of buffer */
+                               memset(dst, 0x2a, count);
+                       }
+                       *z1t = cpu_to_le16(new_z1);     /* now send data */
+               }
+
 next_t_frame:
                count = bch->tx_skb->len - bch->tx_idx;
                /* maximum fill shall be HFCPCI_BTRANS_MAX */
@@ -1482,11 +1510,17 @@ deactivate_bchannel(struct bchannel *bch)
 static int
 channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
 {
-       int                     ret = 0;
+       int     ret = 0;
 
        switch (cq->op) {
        case MISDN_CTRL_GETOP:
-               cq->op = 0;
+               cq->op = MISDN_CTRL_FILL_EMPTY;
+               break;
+       case MISDN_CTRL_FILL_EMPTY: /* fill fifo, if empty */
+               test_and_set_bit(FLG_FILLEMPTY, &bch->Flags);
+               if (debug & DEBUG_HW_OPEN)
+                       printk(KERN_DEBUG "%s: FILL_EMPTY request (nr=%d "
+                               "off=%d)\n", __func__, bch->nr, !!cq->p1);
                break;
        default:
                printk(KERN_WARNING "%s: unknown Op %x\n", __func__, cq->op);
@@ -1679,7 +1713,7 @@ hfcpci_l2l1B(struct mISDNchannel *ch, struct sk_buff *skb)
  * called for card init message
  */
 
-void
+static void
 inithfcpci(struct hfc_pci *hc)
 {
        printk(KERN_DEBUG "inithfcpci: entered\n");
@@ -1904,6 +1938,7 @@ open_bchannel(struct hfc_pci *hc, struct channel_req *rq)
        bch = &hc->bch[rq->adr.channel - 1];
        if (test_and_set_bit(FLG_OPEN, &bch->Flags))
                return -EBUSY; /* b-channel can be only open once */
+       test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags);
        bch->ch.protocol = rq->protocol;
        rq->ch = &bch->ch; /* TODO: E-channel */
        if (!try_module_get(THIS_MODULE))
@@ -1929,7 +1964,8 @@ hfc_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
        switch (cmd) {
        case OPEN_CHANNEL:
                rq = arg;
-               if (rq->adr.channel == 0)
+               if ((rq->protocol == ISDN_P_TE_S0) ||
+                   (rq->protocol == ISDN_P_NT_S0))
                        err = open_dchannel(hc, ch, rq);
                else
                        err = open_bchannel(hc, rq);
@@ -1966,7 +2002,7 @@ setup_hw(struct hfc_pci *hc)
                printk(KERN_WARNING "HFC-PCI: No IRQ for PCI card found\n");
                return 1;
        }
-       hc->hw.pci_io = (char *)(ulong)hc->pdev->resource[1].start;
+       hc->hw.pci_io = (char __iomem *)(unsigned long)hc->pdev->resource[1].start;
 
        if (!hc->hw.pci_io) {
                printk(KERN_WARNING "HFC-PCI: No IO-Mem for PCI card found\n");
@@ -2041,9 +2077,6 @@ setup_card(struct hfc_pci *card)
        u_long          flags;
        char            name[MISDN_MAX_IDLEN];
 
-       if (HFC_cnt >= MAX_CARDS)
-               return -EINVAL; /* maybe better value */
-
        card->dch.debug = debug;
        spin_lock_init(&card->lock);
        mISDN_initdchannel(&card->dch, MAX_DFRAME_LEN_L1, ph_state);