1 /*************************************************************************/
2 /* $Id: hfc4s8s_l1.c,v 1.10 2005/02/09 16:31:09 martinb1 Exp $ */
3 /* HFC-4S/8S low layer interface for Cologne Chip HFC-4S/8S isdn chips */
4 /* The low layer (L1) is implemented as a loadable module for usage with */
5 /* the HiSax isdn driver for passive cards. */
7 /* Author: Werner Cornelius */
8 /* (C) 2003 Cornelius Consult (werner@cornelius-consult.de) */
10 /* Driver maintained by Cologne Chip */
11 /* - Martin Bachem, support@colognechip.com */
13 /* This driver only works with chip revisions >= 1, older revision 0 */
14 /* engineering samples (only first manufacturer sample cards) will not */
15 /* work and are rejected by the driver. */
17 /* This file distributed under the GNU GPL. */
19 /* See Version History at the end of this file */
21 /*************************************************************************/
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/pci.h>
26 #include <linux/interrupt.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/timer.h>
30 #include <linux/skbuff.h>
31 #include <linux/wait.h>
34 #include "hfc4s8s_l1.h"
36 static const char hfc4s8s_rev[] = "Revision: 1.10";
38 /***************************************************************/
39 /* adjustable transparent mode fifo threshold */
40 /* The value defines the used fifo threshold with the equation */
42 /* notify number of bytes = 2 * 2 ^ TRANS_FIFO_THRES */
44 /* The default value is 5 which results in a buffer size of 64 */
45 /* and an interrupt rate of 8ms. */
46 /* The maximum value is 7 due to fifo size restrictions. */
47 /* Values below 3-4 are not recommended due to high interrupt */
48 /* load of the processor. For non critical applications the */
49 /* value should be raised to 7 to reduce any interrupt overhead*/
50 /***************************************************************/
51 #define TRANS_FIFO_THRES 5
56 #define CLOCKMODE_0 0 /* ext. 24.576 MhZ clk freq, int. single clock mode */
57 #define CLOCKMODE_1 1 /* ext. 49.576 MhZ clk freq, int. single clock mode */
58 #define CHIP_ID_SHIFT 4
60 #define MAX_D_FRAME_SIZE 270
61 #define MAX_B_FRAME_SIZE 1536
62 #define TRANS_TIMER_MODE (TRANS_FIFO_THRES & 0xf)
63 #define TRANS_FIFO_BYTES (2 << TRANS_FIFO_THRES)
64 #define MAX_F_CNT 0x0f
66 #define CLKDEL_NT 0x6c
71 #define L1_TIMER_T4 2 /* minimum in jiffies */
72 #define L1_TIMER_T3 (7 * HZ) /* activation timeout */
73 #define L1_TIMER_T1 ((120 * HZ) / 1000) /* NT mode deactivation timeout */
81 /* private driver_data */
89 static const struct pci_device_id hfc4s8s_ids[] = {
90 {.vendor = PCI_VENDOR_ID_CCD,
91 .device = PCI_DEVICE_ID_4S,
95 (unsigned long) &((hfc4s8s_param) {CHIP_ID_4S, CLOCKMODE_0, 4,
96 "HFC-4S Evaluation Board"}),
98 {.vendor = PCI_VENDOR_ID_CCD,
99 .device = PCI_DEVICE_ID_8S,
103 (unsigned long) &((hfc4s8s_param) {CHIP_ID_8S, CLOCKMODE_0, 8,
104 "HFC-8S Evaluation Board"}),
106 {.vendor = PCI_VENDOR_ID_CCD,
107 .device = PCI_DEVICE_ID_4S,
111 (unsigned long) &((hfc4s8s_param) {CHIP_ID_4S, CLOCKMODE_1, 4,
114 {.vendor = PCI_VENDOR_ID_CCD,
115 .device = PCI_DEVICE_ID_8S,
119 (unsigned long) &((hfc4s8s_param) {CHIP_ID_8S, CLOCKMODE_1, 8,
125 MODULE_DEVICE_TABLE(pci, hfc4s8s_ids);
127 MODULE_AUTHOR("Werner Cornelius, werner@cornelius-consult.de");
128 MODULE_DESCRIPTION("ISDN layer 1 for Cologne Chip HFC-4S/8S chips");
129 MODULE_LICENSE("GPL");
134 struct hfc4s8s_btype {
136 struct hisax_b_if b_if;
137 struct hfc4s8s_l1 *l1p;
138 struct sk_buff_head tx_queue;
139 struct sk_buff *tx_skb;
140 struct sk_buff *rx_skb;
151 struct _hfc4s8s_hw *hw; /* pointer to hardware area */
152 int l1_state; /* actual l1 state */
153 struct timer_list l1_timer; /* layer 1 timer structure */
154 int nt_mode; /* set to nt mode */
155 int st_num; /* own index */
156 int enabled; /* interface is enabled */
157 struct sk_buff_head d_tx_queue; /* send queue */
158 int tx_cnt; /* bytes to send */
159 struct hisax_d_if d_if; /* D-channel interface */
160 struct hfc4s8s_btype b_ch[2]; /* B-channel data */
161 struct hisax_b_if *b_table[2];
164 /**********************/
165 /* hardware structure */
166 /**********************/
167 typedef struct _hfc4s8s_hw {
178 hfc4s8s_param driver_data;
181 struct work_struct tqueue;
182 struct hfc4s8s_l1 l1[HFC_MAX_ST];
187 volatile u_char r_irq_statech; /* active isdn l1 status */
188 u_char r_irqmsk_statchg; /* enabled isdn status ints */
189 u_char r_irq_fifo_blx[8]; /* fifo status registers */
190 u_char fifo_rx_trans_enables[8]; /* mask for enabled transparent rx fifos */
191 u_char fifo_slow_timer_service[8]; /* mask for fifos needing slower timer service */
192 volatile u_char r_irq_oview; /* contents of overview register */
193 volatile u_char timer_irq;
194 int timer_usg_cnt; /* number of channels using timer */
200 /* inline functions io mapped */
202 SetRegAddr(hfc4s8s_hw *a, u_char b)
204 outb(b, (a->iobase) + 4);
208 GetRegAddr(hfc4s8s_hw *a)
210 return (inb((volatile u_int) (a->iobase + 4)));
215 Write_hfc8(hfc4s8s_hw *a, u_char b, u_char c)
222 fWrite_hfc8(hfc4s8s_hw *a, u_char c)
228 fWrite_hfc32(hfc4s8s_hw *a, u_long c)
234 Read_hfc8(hfc4s8s_hw *a, u_char b)
237 return (inb((volatile u_int) a->iobase));
241 fRead_hfc8(hfc4s8s_hw *a)
243 return (inb((volatile u_int) a->iobase));
247 static inline u_short
248 Read_hfc16(hfc4s8s_hw *a, u_char b)
251 return (inw((volatile u_int) a->iobase));
255 fRead_hfc32(hfc4s8s_hw *a)
257 return (inl((volatile u_int) a->iobase));
261 wait_busy(hfc4s8s_hw *a)
263 SetRegAddr(a, R_STATUS);
264 while (inb((volatile u_int) a->iobase) & M_BUSY);
267 #define PCI_ENA_REGIO 0x01
269 /******************************************************/
270 /* function to read critical counter registers that */
271 /* may be updated by the chip during read */
272 /******************************************************/
274 Read_hfc8_stable(hfc4s8s_hw *hw, int reg)
278 ref8 = Read_hfc8(hw, reg);
279 while (((in8 = Read_hfc8(hw, reg)) != ref8)) {
286 Read_hfc16_stable(hfc4s8s_hw *hw, int reg)
291 ref16 = Read_hfc16(hw, reg);
292 while (((in16 = Read_hfc16(hw, reg)) != ref16)) {
298 /*****************************/
299 /* D-channel call from HiSax */
300 /*****************************/
302 dch_l2l1(struct hisax_d_if *iface, int pr, void *arg)
304 struct hfc4s8s_l1 *l1 = iface->ifc.priv;
305 struct sk_buff *skb = (struct sk_buff *) arg;
310 case (PH_DATA | REQUEST):
315 spin_lock_irqsave(&l1->lock, flags);
316 skb_queue_tail(&l1->d_tx_queue, skb);
317 if ((skb_queue_len(&l1->d_tx_queue) == 1) &&
319 l1->hw->mr.r_irq_fifo_blx[l1->st_num] |=
321 spin_unlock_irqrestore(&l1->lock, flags);
322 schedule_work(&l1->hw->tqueue);
324 spin_unlock_irqrestore(&l1->lock, flags);
327 case (PH_ACTIVATE | REQUEST):
331 if (l1->l1_state < 6) {
332 spin_lock_irqsave(&l1->lock,
335 Write_hfc8(l1->hw, R_ST_SEL,
337 Write_hfc8(l1->hw, A_ST_WR_STA,
339 mod_timer(&l1->l1_timer,
340 jiffies + L1_TIMER_T3);
341 spin_unlock_irqrestore(&l1->lock,
343 } else if (l1->l1_state == 7)
344 l1->d_if.ifc.l1l2(&l1->d_if.ifc,
349 if (l1->l1_state != 3) {
350 spin_lock_irqsave(&l1->lock,
352 Write_hfc8(l1->hw, R_ST_SEL,
354 Write_hfc8(l1->hw, A_ST_WR_STA,
356 spin_unlock_irqrestore(&l1->lock,
358 } else if (l1->l1_state == 3)
359 l1->d_if.ifc.l1l2(&l1->d_if.ifc,
368 "HFC-4S/8S: Unknown D-chan cmd 0x%x received, ignored\n",
373 l1->d_if.ifc.l1l2(&l1->d_if.ifc,
374 PH_DEACTIVATE | INDICATION, NULL);
377 /*****************************/
378 /* B-channel call from HiSax */
379 /*****************************/
381 bch_l2l1(struct hisax_if *ifc, int pr, void *arg)
383 struct hfc4s8s_btype *bch = ifc->priv;
384 struct hfc4s8s_l1 *l1 = bch->l1p;
385 struct sk_buff *skb = (struct sk_buff *) arg;
386 long mode = (long) arg;
391 case (PH_DATA | REQUEST):
392 if (!l1->enabled || (bch->mode == L1_MODE_NULL)) {
396 spin_lock_irqsave(&l1->lock, flags);
397 skb_queue_tail(&bch->tx_queue, skb);
398 if (!bch->tx_skb && (bch->tx_cnt <= 0)) {
399 l1->hw->mr.r_irq_fifo_blx[l1->st_num] |=
400 ((bch->bchan == 1) ? 1 : 4);
401 spin_unlock_irqrestore(&l1->lock, flags);
402 schedule_work(&l1->hw->tqueue);
404 spin_unlock_irqrestore(&l1->lock, flags);
407 case (PH_ACTIVATE | REQUEST):
408 case (PH_DEACTIVATE | REQUEST):
411 if (pr == (PH_DEACTIVATE | REQUEST))
416 spin_lock_irqsave(&l1->lock,
418 l1->hw->mr.timer_usg_cnt++;
420 fifo_slow_timer_service[l1->
425 Write_hfc8(l1->hw, R_FIFO,
430 Write_hfc8(l1->hw, A_CON_HDLC, 0xc); /* HDLC mode, flag fill, connect ST */
431 Write_hfc8(l1->hw, A_SUBCH_CFG, 0); /* 8 bits */
432 Write_hfc8(l1->hw, A_IRQ_MSK, 1); /* enable TX interrupts for hdlc */
433 Write_hfc8(l1->hw, A_INC_RES_FIFO, 2); /* reset fifo */
436 Write_hfc8(l1->hw, R_FIFO,
441 Write_hfc8(l1->hw, A_CON_HDLC, 0xc); /* HDLC mode, flag fill, connect ST */
442 Write_hfc8(l1->hw, A_SUBCH_CFG, 0); /* 8 bits */
443 Write_hfc8(l1->hw, A_IRQ_MSK, 1); /* enable RX interrupts for hdlc */
444 Write_hfc8(l1->hw, A_INC_RES_FIFO, 2); /* reset fifo */
446 Write_hfc8(l1->hw, R_ST_SEL,
448 l1->hw->mr.r_ctrl0 |=
450 Write_hfc8(l1->hw, A_ST_CTRL0,
452 bch->mode = L1_MODE_HDLC;
453 spin_unlock_irqrestore(&l1->lock,
456 bch->b_if.ifc.l1l2(&bch->b_if.ifc,
463 spin_lock_irqsave(&l1->lock,
466 fifo_rx_trans_enables[l1->
471 l1->hw->mr.timer_usg_cnt++;
472 Write_hfc8(l1->hw, R_FIFO,
477 Write_hfc8(l1->hw, A_CON_HDLC, 0xf); /* Transparent mode, 1 fill, connect ST */
478 Write_hfc8(l1->hw, A_SUBCH_CFG, 0); /* 8 bits */
479 Write_hfc8(l1->hw, A_IRQ_MSK, 0); /* disable TX interrupts */
480 Write_hfc8(l1->hw, A_INC_RES_FIFO, 2); /* reset fifo */
483 Write_hfc8(l1->hw, R_FIFO,
488 Write_hfc8(l1->hw, A_CON_HDLC, 0xf); /* Transparent mode, 1 fill, connect ST */
489 Write_hfc8(l1->hw, A_SUBCH_CFG, 0); /* 8 bits */
490 Write_hfc8(l1->hw, A_IRQ_MSK, 0); /* disable RX interrupts */
491 Write_hfc8(l1->hw, A_INC_RES_FIFO, 2); /* reset fifo */
493 Write_hfc8(l1->hw, R_ST_SEL,
495 l1->hw->mr.r_ctrl0 |=
497 Write_hfc8(l1->hw, A_ST_CTRL0,
499 bch->mode = L1_MODE_TRANS;
500 spin_unlock_irqrestore(&l1->lock,
503 bch->b_if.ifc.l1l2(&bch->b_if.ifc,
510 if (bch->mode == L1_MODE_NULL)
512 spin_lock_irqsave(&l1->lock,
515 fifo_slow_timer_service[l1->
521 fifo_rx_trans_enables[l1->
526 l1->hw->mr.timer_usg_cnt--;
527 Write_hfc8(l1->hw, R_FIFO,
532 Write_hfc8(l1->hw, A_IRQ_MSK, 0); /* disable TX interrupts */
534 Write_hfc8(l1->hw, R_FIFO,
539 Write_hfc8(l1->hw, A_IRQ_MSK, 0); /* disable RX interrupts */
540 Write_hfc8(l1->hw, R_ST_SEL,
542 l1->hw->mr.r_ctrl0 &=
544 Write_hfc8(l1->hw, A_ST_CTRL0,
546 spin_unlock_irqrestore(&l1->lock,
549 bch->mode = L1_MODE_NULL;
550 bch->b_if.ifc.l1l2(&bch->b_if.ifc,
555 dev_kfree_skb(bch->tx_skb);
559 dev_kfree_skb(bch->rx_skb);
562 skb_queue_purge(&bch->tx_queue);
568 /* timer is only used when at least one b channel */
569 /* is set up to transparent mode */
570 if (l1->hw->mr.timer_usg_cnt) {
571 Write_hfc8(l1->hw, R_IRQMSK_MISC,
574 Write_hfc8(l1->hw, R_IRQMSK_MISC, 0);
581 "HFC-4S/8S: Unknown B-chan cmd 0x%x received, ignored\n",
586 bch->b_if.ifc.l1l2(&bch->b_if.ifc,
587 PH_DEACTIVATE | INDICATION, NULL);
590 /**************************/
591 /* layer 1 timer function */
592 /**************************/
594 hfc_l1_timer(struct timer_list *t)
596 struct hfc4s8s_l1 *l1 = from_timer(l1, t, l1_timer);
602 spin_lock_irqsave(&l1->lock, flags);
605 Write_hfc8(l1->hw, R_ST_SEL, l1->st_num);
606 Write_hfc8(l1->hw, A_ST_WR_STA, 0x11);
607 spin_unlock_irqrestore(&l1->lock, flags);
608 l1->d_if.ifc.l1l2(&l1->d_if.ifc,
609 PH_DEACTIVATE | INDICATION, NULL);
610 spin_lock_irqsave(&l1->lock, flags);
612 Write_hfc8(l1->hw, A_ST_WR_STA, 0x1);
613 spin_unlock_irqrestore(&l1->lock, flags);
615 /* activation timed out */
616 Write_hfc8(l1->hw, R_ST_SEL, l1->st_num);
617 Write_hfc8(l1->hw, A_ST_WR_STA, 0x13);
618 spin_unlock_irqrestore(&l1->lock, flags);
619 l1->d_if.ifc.l1l2(&l1->d_if.ifc,
620 PH_DEACTIVATE | INDICATION, NULL);
621 spin_lock_irqsave(&l1->lock, flags);
622 Write_hfc8(l1->hw, R_ST_SEL, l1->st_num);
623 Write_hfc8(l1->hw, A_ST_WR_STA, 0x3);
624 spin_unlock_irqrestore(&l1->lock, flags);
628 /****************************************/
629 /* a complete D-frame has been received */
630 /****************************************/
632 rx_d_frame(struct hfc4s8s_l1 *l1p, int ech)
644 Write_hfc8(l1p->hw, R_FIFO,
645 (l1p->st_num * 8 + ((ech) ? 7 : 5)));
648 f1 = Read_hfc8_stable(l1p->hw, A_F1);
649 f2 = Read_hfc8(l1p->hw, A_F2);
652 df = MAX_F_CNT + 1 + f1 - f2;
657 return; /* no complete frame in fifo */
659 z1 = Read_hfc16_stable(l1p->hw, A_Z1);
660 z2 = Read_hfc16(l1p->hw, A_Z2);
666 if (!(skb = dev_alloc_skb(MAX_D_FRAME_SIZE))) {
668 "HFC-4S/8S: Could not allocate D/E "
669 "channel receive buffer");
670 Write_hfc8(l1p->hw, A_INC_RES_FIFO, 2);
675 if (((z1 < 4) || (z1 > MAX_D_FRAME_SIZE))) {
678 /* remove errornous D frame */
681 Write_hfc8(l1p->hw, A_INC_RES_FIFO, 2);
685 /* read errornous D frame */
686 SetRegAddr(l1p->hw, A_FIFO_DATA0);
689 fRead_hfc32(l1p->hw);
696 Write_hfc8(l1p->hw, A_INC_RES_FIFO, 1);
704 SetRegAddr(l1p->hw, A_FIFO_DATA0);
707 *((unsigned long *) cp) = fRead_hfc32(l1p->hw);
713 *cp++ = fRead_hfc8(l1p->hw);
715 Write_hfc8(l1p->hw, A_INC_RES_FIFO, 1); /* increment f counter */
721 skb->len = (cp - skb->data) - 2;
723 l1p->d_if.ifc.l1l2(&l1p->d_if.ifc,
724 PH_DATA_E | INDICATION,
727 l1p->d_if.ifc.l1l2(&l1p->d_if.ifc,
728 PH_DATA | INDICATION,
734 /*************************************************************/
735 /* a B-frame has been received (perhaps not fully completed) */
736 /*************************************************************/
738 rx_b_frame(struct hfc4s8s_btype *bch)
740 int z1, z2, hdlc_complete;
742 struct hfc4s8s_l1 *l1 = bch->l1p;
745 if (!l1->enabled || (bch->mode == L1_MODE_NULL))
750 Write_hfc8(l1->hw, R_FIFO,
751 (l1->st_num * 8 + ((bch->bchan == 1) ? 1 : 3)));
754 if (bch->mode == L1_MODE_HDLC) {
755 f1 = Read_hfc8_stable(l1->hw, A_F1);
756 f2 = Read_hfc8(l1->hw, A_F2);
757 hdlc_complete = ((f1 ^ f2) & MAX_F_CNT);
760 z1 = Read_hfc16_stable(l1->hw, A_Z1);
761 z2 = Read_hfc16(l1->hw, A_Z2);
771 if (!(skb = bch->rx_skb)) {
774 dev_alloc_skb((bch->mode ==
776 : (MAX_B_FRAME_SIZE + 3)))) {
778 "HFC-4S/8S: Could not allocate B "
779 "channel receive buffer");
782 bch->rx_ptr = skb->data;
786 skb->len = (bch->rx_ptr - skb->data) + z1;
788 /* HDLC length check */
789 if ((bch->mode == L1_MODE_HDLC) &&
790 ((hdlc_complete && (skb->len < 4)) ||
791 (skb->len > (MAX_B_FRAME_SIZE + 3)))) {
794 bch->rx_ptr = skb->data;
795 Write_hfc8(l1->hw, A_INC_RES_FIFO, 2); /* reset fifo */
799 SetRegAddr(l1->hw, A_FIFO_DATA0);
802 *((unsigned long *) bch->rx_ptr) =
809 *(bch->rx_ptr++) = fRead_hfc8(l1->hw);
812 /* increment f counter */
813 Write_hfc8(l1->hw, A_INC_RES_FIFO, 1);
820 bch->rx_ptr = skb->data;
825 if (hdlc_complete || (bch->mode == L1_MODE_TRANS)) {
828 bch->b_if.ifc.l1l2(&bch->b_if.ifc,
829 PH_DATA | INDICATION, skb);
835 /********************************************/
836 /* a D-frame has been/should be transmitted */
837 /********************************************/
839 tx_d_frame(struct hfc4s8s_l1 *l1p)
846 if (l1p->l1_state != 7)
850 Write_hfc8(l1p->hw, R_FIFO, (l1p->st_num * 8 + 4));
853 f1 = Read_hfc8(l1p->hw, A_F1);
854 f2 = Read_hfc8_stable(l1p->hw, A_F2);
856 if ((f1 ^ f2) & MAX_F_CNT)
857 return; /* fifo is still filled */
859 if (l1p->tx_cnt > 0) {
862 l1p->d_if.ifc.l1l2(&l1p->d_if.ifc, PH_DATA | CONFIRM,
866 if ((skb = skb_dequeue(&l1p->d_tx_queue))) {
869 SetRegAddr(l1p->hw, A_FIFO_DATA0);
872 SetRegAddr(l1p->hw, A_FIFO_DATA0);
873 fWrite_hfc32(l1p->hw, *(unsigned long *) cp);
879 fWrite_hfc8(l1p->hw, *cp++);
881 l1p->tx_cnt = skb->truesize;
882 Write_hfc8(l1p->hw, A_INC_RES_FIFO, 1); /* increment f counter */
889 /******************************************************/
890 /* a B-frame may be transmitted (or is not completed) */
891 /******************************************************/
893 tx_b_frame(struct hfc4s8s_btype *bch)
896 struct hfc4s8s_l1 *l1 = bch->l1p;
898 int cnt, max, hdlc_num;
901 if (!l1->enabled || (bch->mode == L1_MODE_NULL))
905 Write_hfc8(l1->hw, R_FIFO,
906 (l1->st_num * 8 + ((bch->bchan == 1) ? 0 : 2)));
910 if (bch->mode == L1_MODE_HDLC) {
911 hdlc_num = Read_hfc8(l1->hw, A_F1) & MAX_F_CNT;
913 (Read_hfc8_stable(l1->hw, A_F2) & MAX_F_CNT);
917 break; /* fifo still filled up with hdlc frames */
921 if (!(skb = bch->tx_skb)) {
922 if (!(skb = skb_dequeue(&bch->tx_queue))) {
923 l1->hw->mr.fifo_slow_timer_service[l1->
925 &= ~((bch->bchan == 1) ? 1 : 4);
926 break; /* list empty */
933 l1->hw->mr.fifo_slow_timer_service[l1->st_num] |=
934 ((bch->bchan == 1) ? 1 : 4);
936 l1->hw->mr.fifo_slow_timer_service[l1->st_num] &=
937 ~((bch->bchan == 1) ? 1 : 4);
939 max = Read_hfc16_stable(l1->hw, A_Z2);
940 max -= Read_hfc16(l1->hw, A_Z1);
946 break; /* don't write to small amounts of bytes */
948 cnt = skb->len - bch->tx_cnt;
951 cp = skb->data + bch->tx_cnt;
954 SetRegAddr(l1->hw, A_FIFO_DATA0);
956 fWrite_hfc32(l1->hw, *(unsigned long *) cp);
962 fWrite_hfc8(l1->hw, *cp++);
964 if (bch->tx_cnt >= skb->len) {
965 if (bch->mode == L1_MODE_HDLC) {
966 /* increment f counter */
967 Write_hfc8(l1->hw, A_INC_RES_FIFO, 1);
969 ack_len += skb->truesize;
975 Write_hfc8(l1->hw, R_FIFO,
977 ((bch->bchan == 1) ? 0 : 2)));
982 bch->b_if.ifc.l1l2((struct hisax_if *) &bch->b_if,
983 PH_DATA | CONFIRM, (void *) ack_len);
986 /*************************************/
987 /* bottom half handler for interrupt */
988 /*************************************/
990 hfc4s8s_bh(struct work_struct *work)
992 hfc4s8s_hw *hw = container_of(work, hfc4s8s_hw, tqueue);
994 struct hfc4s8s_l1 *l1p;
995 volatile u_char *fifo_stat;
998 /* handle layer 1 state changes */
1002 if ((b & hw->mr.r_irq_statech)) {
1003 /* reset l1 event */
1004 hw->mr.r_irq_statech &= ~b;
1007 u_char oldstate = l1p->l1_state;
1009 Write_hfc8(l1p->hw, R_ST_SEL,
1016 && (l1p->l1_state != 3))
1017 l1p->d_if.ifc.l1l2(&l1p->
1025 if (l1p->l1_state != 2) {
1026 del_timer(&l1p->l1_timer);
1027 if (l1p->l1_state == 3) {
1037 /* allow transition */
1038 Write_hfc8(hw, A_ST_WR_STA,
1040 mod_timer(&l1p->l1_timer,
1045 "HFC-4S/8S: NT ch %d l1 state %d -> %d\n",
1046 l1p->st_num, oldstate,
1049 u_char oldstate = l1p->l1_state;
1051 Write_hfc8(l1p->hw, R_ST_SEL,
1057 if (((l1p->l1_state == 3) &&
1059 (oldstate == 8))) ||
1062 && (l1p->l1_state == 8))) {
1063 mod_timer(&l1p->l1_timer,
1067 if (l1p->l1_state == 7) {
1079 if (l1p->l1_state == 3) {
1094 "HFC-4S/8S: TE %d ch %d l1 state %d -> %d\n",
1096 l1p->st_num, oldstate,
1105 /* now handle the fifos */
1107 fifo_stat = hw->mr.r_irq_fifo_blx;
1109 while (idx < hw->driver_data.max_st_ports) {
1111 if (hw->mr.timer_irq) {
1112 *fifo_stat |= hw->mr.fifo_rx_trans_enables[idx];
1113 if (hw->fifo_sched_cnt <= 0) {
1115 hw->mr.fifo_slow_timer_service[l1p->
1119 /* ignore fifo 6 (TX E fifo) */
1120 *fifo_stat &= 0xff - 0x40;
1122 while (*fifo_stat) {
1124 if (!l1p->nt_mode) {
1125 /* RX Fifo has data to read */
1126 if ((*fifo_stat & 0x20)) {
1127 *fifo_stat &= ~0x20;
1130 /* E Fifo has data to read */
1131 if ((*fifo_stat & 0x80)) {
1132 *fifo_stat &= ~0x80;
1135 /* TX Fifo completed send */
1136 if ((*fifo_stat & 0x10)) {
1137 *fifo_stat &= ~0x10;
1141 /* B1 RX Fifo has data to read */
1142 if ((*fifo_stat & 0x2)) {
1144 rx_b_frame(l1p->b_ch);
1146 /* B1 TX Fifo has send completed */
1147 if ((*fifo_stat & 0x1)) {
1149 tx_b_frame(l1p->b_ch);
1151 /* B2 RX Fifo has data to read */
1152 if ((*fifo_stat & 0x8)) {
1154 rx_b_frame(l1p->b_ch + 1);
1156 /* B2 TX Fifo has send completed */
1157 if ((*fifo_stat & 0x4)) {
1159 tx_b_frame(l1p->b_ch + 1);
1167 if (hw->fifo_sched_cnt <= 0)
1168 hw->fifo_sched_cnt += (1 << (7 - TRANS_TIMER_MODE));
1169 hw->mr.timer_irq = 0; /* clear requested timer irq */
1172 /*********************/
1173 /* interrupt handler */
1174 /*********************/
1176 hfc4s8s_interrupt(int intno, void *dev_id)
1178 hfc4s8s_hw *hw = dev_id;
1180 volatile u_char *ovp;
1184 if (!hw || !(hw->mr.r_irq_ctrl & M_GLOB_IRQ_EN))
1187 /* read current selected regsister */
1188 old_ioreg = GetRegAddr(hw);
1190 /* Layer 1 State change */
1191 hw->mr.r_irq_statech |=
1192 (Read_hfc8(hw, R_SCI) & hw->mr.r_irqmsk_statchg);
1194 (b = (Read_hfc8(hw, R_STATUS) & (M_MISC_IRQSTA | M_FR_IRQSTA)))
1195 && !hw->mr.r_irq_statech) {
1196 SetRegAddr(hw, old_ioreg);
1201 if (Read_hfc8(hw, R_IRQ_MISC) & M_TI_IRQ) {
1202 hw->mr.timer_irq = 1;
1203 hw->fifo_sched_cnt--;
1207 if ((ovr = Read_hfc8(hw, R_IRQ_OVIEW))) {
1208 hw->mr.r_irq_oview |= ovr;
1209 idx = R_IRQ_FIFO_BL0;
1210 ovp = hw->mr.r_irq_fifo_blx;
1213 *ovp |= Read_hfc8(hw, idx);
1221 /* queue the request to allow other cards to interrupt */
1222 schedule_work(&hw->tqueue);
1224 SetRegAddr(hw, old_ioreg);
1226 } /* hfc4s8s_interrupt */
1228 /***********************************************************************/
1229 /* reset the complete chip, don't release the chips irq but disable it */
1230 /***********************************************************************/
1232 chipreset(hfc4s8s_hw *hw)
1236 spin_lock_irqsave(&hw->lock, flags);
1237 Write_hfc8(hw, R_CTRL, 0); /* use internal RAM */
1238 Write_hfc8(hw, R_RAM_MISC, 0); /* 32k*8 RAM */
1239 Write_hfc8(hw, R_FIFO_MD, 0); /* fifo mode 386 byte/fifo simple mode */
1240 Write_hfc8(hw, R_CIRM, M_SRES); /* reset chip */
1241 hw->mr.r_irq_ctrl = 0; /* interrupt is inactive */
1242 spin_unlock_irqrestore(&hw->lock, flags);
1245 Write_hfc8(hw, R_CIRM, 0); /* disable reset */
1248 Write_hfc8(hw, R_PCM_MD0, M_PCM_MD); /* master mode */
1249 Write_hfc8(hw, R_RAM_MISC, M_FZ_MD); /* transmit fifo option */
1250 if (hw->driver_data.clock_mode == 1)
1251 Write_hfc8(hw, R_BRG_PCM_CFG, M_PCM_CLK); /* PCM clk / 2 */
1252 Write_hfc8(hw, R_TI_WD, TRANS_TIMER_MODE); /* timer interval */
1254 memset(&hw->mr, 0, sizeof(hw->mr));
1257 /********************************************/
1258 /* disable/enable hardware in nt or te mode */
1259 /********************************************/
1261 hfc_hardware_enable(hfc4s8s_hw *hw, int enable, int nt_mode)
1268 /* save system vars */
1269 hw->nt_mode = nt_mode;
1271 /* enable fifo and state irqs, but not global irq enable */
1272 hw->mr.r_irq_ctrl = M_FIFO_IRQ;
1273 Write_hfc8(hw, R_IRQ_CTRL, hw->mr.r_irq_ctrl);
1274 hw->mr.r_irqmsk_statchg = 0;
1275 Write_hfc8(hw, R_SCI_MSK, hw->mr.r_irqmsk_statchg);
1276 Write_hfc8(hw, R_PWM_MD, 0x80);
1277 Write_hfc8(hw, R_PWM1, 26);
1279 Write_hfc8(hw, R_ST_SYNC, M_AUTO_SYNC);
1281 /* enable the line interfaces and fifos */
1282 for (i = 0; i < hw->driver_data.max_st_ports; i++) {
1283 hw->mr.r_irqmsk_statchg |= (1 << i);
1284 Write_hfc8(hw, R_SCI_MSK, hw->mr.r_irqmsk_statchg);
1285 Write_hfc8(hw, R_ST_SEL, i);
1286 Write_hfc8(hw, A_ST_CLK_DLY,
1287 ((nt_mode) ? CLKDEL_NT : CLKDEL_TE));
1288 hw->mr.r_ctrl0 = ((nt_mode) ? CTRL0_NT : CTRL0_TE);
1289 Write_hfc8(hw, A_ST_CTRL0, hw->mr.r_ctrl0);
1290 Write_hfc8(hw, A_ST_CTRL2, 3);
1291 Write_hfc8(hw, A_ST_WR_STA, 0); /* enable state machine */
1293 hw->l1[i].enabled = 1;
1294 hw->l1[i].nt_mode = nt_mode;
1298 Write_hfc8(hw, R_FIFO, i * 8 + 7); /* E fifo */
1300 Write_hfc8(hw, A_CON_HDLC, 0x11); /* HDLC mode, 1 fill, connect ST */
1301 Write_hfc8(hw, A_SUBCH_CFG, 2); /* only 2 bits */
1302 Write_hfc8(hw, A_IRQ_MSK, 1); /* enable interrupt */
1303 Write_hfc8(hw, A_INC_RES_FIFO, 2); /* reset fifo */
1306 /* setup D RX-fifo */
1307 Write_hfc8(hw, R_FIFO, i * 8 + 5); /* RX fifo */
1309 Write_hfc8(hw, A_CON_HDLC, 0x11); /* HDLC mode, 1 fill, connect ST */
1310 Write_hfc8(hw, A_SUBCH_CFG, 2); /* only 2 bits */
1311 Write_hfc8(hw, A_IRQ_MSK, 1); /* enable interrupt */
1312 Write_hfc8(hw, A_INC_RES_FIFO, 2); /* reset fifo */
1315 /* setup D TX-fifo */
1316 Write_hfc8(hw, R_FIFO, i * 8 + 4); /* TX fifo */
1318 Write_hfc8(hw, A_CON_HDLC, 0x11); /* HDLC mode, 1 fill, connect ST */
1319 Write_hfc8(hw, A_SUBCH_CFG, 2); /* only 2 bits */
1320 Write_hfc8(hw, A_IRQ_MSK, 1); /* enable interrupt */
1321 Write_hfc8(hw, A_INC_RES_FIFO, 2); /* reset fifo */
1325 sprintf(if_name, "hfc4s8s_%d%d_", hw->cardnum, i);
1328 (&hw->l1[i].d_if, hw->l1[i].b_table, if_name,
1329 ((nt_mode) ? 3 : 2))) {
1331 hw->l1[i].enabled = 0;
1332 hw->mr.r_irqmsk_statchg &= ~(1 << i);
1333 Write_hfc8(hw, R_SCI_MSK,
1334 hw->mr.r_irqmsk_statchg);
1336 "HFC-4S/8S: Unable to register S/T device %s, break\n",
1341 spin_lock_irqsave(&hw->lock, flags);
1342 hw->mr.r_irq_ctrl |= M_GLOB_IRQ_EN;
1343 Write_hfc8(hw, R_IRQ_CTRL, hw->mr.r_irq_ctrl);
1344 spin_unlock_irqrestore(&hw->lock, flags);
1346 /* disable hardware */
1347 spin_lock_irqsave(&hw->lock, flags);
1348 hw->mr.r_irq_ctrl &= ~M_GLOB_IRQ_EN;
1349 Write_hfc8(hw, R_IRQ_CTRL, hw->mr.r_irq_ctrl);
1350 spin_unlock_irqrestore(&hw->lock, flags);
1352 for (i = hw->driver_data.max_st_ports - 1; i >= 0; i--) {
1353 hw->l1[i].enabled = 0;
1354 hisax_unregister(&hw->l1[i].d_if);
1355 del_timer(&hw->l1[i].l1_timer);
1356 skb_queue_purge(&hw->l1[i].d_tx_queue);
1357 skb_queue_purge(&hw->l1[i].b_ch[0].tx_queue);
1358 skb_queue_purge(&hw->l1[i].b_ch[1].tx_queue);
1362 } /* hfc_hardware_enable */
1364 /******************************************/
1365 /* disable memory mapped ports / io ports */
1366 /******************************************/
1368 release_pci_ports(hfc4s8s_hw *hw)
1370 pci_write_config_word(hw->pdev, PCI_COMMAND, 0);
1372 release_region(hw->iobase, 8);
1375 /*****************************************/
1376 /* enable memory mapped ports / io ports */
1377 /*****************************************/
1379 enable_pci_ports(hfc4s8s_hw *hw)
1381 pci_write_config_word(hw->pdev, PCI_COMMAND, PCI_ENA_REGIO);
1384 /*************************************/
1385 /* initialise the HFC-4s/8s hardware */
1386 /* return 0 on success. */
1387 /*************************************/
1389 setup_instance(hfc4s8s_hw *hw)
1394 for (i = 0; i < HFC_MAX_ST; i++) {
1395 struct hfc4s8s_l1 *l1p;
1398 spin_lock_init(&l1p->lock);
1400 timer_setup(&l1p->l1_timer, hfc_l1_timer, 0);
1402 skb_queue_head_init(&l1p->d_tx_queue);
1403 l1p->d_if.ifc.priv = hw->l1 + i;
1404 l1p->d_if.ifc.l2l1 = (void *) dch_l2l1;
1406 spin_lock_init(&l1p->b_ch[0].lock);
1407 l1p->b_ch[0].b_if.ifc.l2l1 = (void *) bch_l2l1;
1408 l1p->b_ch[0].b_if.ifc.priv = (void *) &l1p->b_ch[0];
1409 l1p->b_ch[0].l1p = hw->l1 + i;
1410 l1p->b_ch[0].bchan = 1;
1411 l1p->b_table[0] = &l1p->b_ch[0].b_if;
1412 skb_queue_head_init(&l1p->b_ch[0].tx_queue);
1414 spin_lock_init(&l1p->b_ch[1].lock);
1415 l1p->b_ch[1].b_if.ifc.l2l1 = (void *) bch_l2l1;
1416 l1p->b_ch[1].b_if.ifc.priv = (void *) &l1p->b_ch[1];
1417 l1p->b_ch[1].l1p = hw->l1 + i;
1418 l1p->b_ch[1].bchan = 2;
1419 l1p->b_table[1] = &l1p->b_ch[1].b_if;
1420 skb_queue_head_init(&l1p->b_ch[1].tx_queue);
1423 enable_pci_ports(hw);
1426 i = Read_hfc8(hw, R_CHIP_ID) >> CHIP_ID_SHIFT;
1427 if (i != hw->driver_data.chip_id) {
1429 "HFC-4S/8S: invalid chip id 0x%x instead of 0x%x, card ignored\n",
1430 i, hw->driver_data.chip_id);
1434 i = Read_hfc8(hw, R_CHIP_RV) & 0xf;
1437 "HFC-4S/8S: chip revision 0 not supported, card ignored\n");
1441 INIT_WORK(&hw->tqueue, hfc4s8s_bh);
1444 (hw->irq, hfc4s8s_interrupt, IRQF_SHARED, hw->card_name, hw)) {
1446 "HFC-4S/8S: unable to alloc irq %d, card ignored\n",
1451 "HFC-4S/8S: found PCI card at iobase 0x%x, irq %d\n",
1452 hw->iobase, hw->irq);
1454 hfc_hardware_enable(hw, 1, 0);
1460 release_pci_ports(hw);
1465 /*****************************************/
1466 /* PCI hotplug interface: probe new card */
1467 /*****************************************/
1469 hfc4s8s_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1472 hfc4s8s_param *driver_data = (hfc4s8s_param *) ent->driver_data;
1475 if (!(hw = kzalloc(sizeof(hfc4s8s_hw), GFP_ATOMIC))) {
1476 printk(KERN_ERR "No kmem for HFC-4S/8S card\n");
1481 err = pci_enable_device(pdev);
1486 hw->cardnum = card_cnt;
1487 sprintf(hw->card_name, "hfc4s8s_%d", hw->cardnum);
1488 printk(KERN_INFO "HFC-4S/8S: found adapter %s (%s) at %s\n",
1489 driver_data->device_name, hw->card_name, pci_name(pdev));
1491 spin_lock_init(&hw->lock);
1493 hw->driver_data = *driver_data;
1494 hw->irq = pdev->irq;
1495 hw->iobase = pci_resource_start(pdev, 0);
1497 if (!request_region(hw->iobase, 8, hw->card_name)) {
1499 "HFC-4S/8S: failed to request address space at 0x%04x\n",
1505 pci_set_drvdata(pdev, hw);
1506 err = setup_instance(hw);
1516 /**************************************/
1517 /* PCI hotplug interface: remove card */
1518 /**************************************/
1520 hfc4s8s_remove(struct pci_dev *pdev)
1522 hfc4s8s_hw *hw = pci_get_drvdata(pdev);
1524 printk(KERN_INFO "HFC-4S/8S: removing card %d\n", hw->cardnum);
1525 hfc_hardware_enable(hw, 0, 0);
1528 free_irq(hw->irq, hw);
1530 release_pci_ports(hw);
1533 pci_disable_device(pdev);
1538 static struct pci_driver hfc4s8s_driver = {
1539 .name = "hfc4s8s_l1",
1540 .probe = hfc4s8s_probe,
1541 .remove = hfc4s8s_remove,
1542 .id_table = hfc4s8s_ids,
1545 /**********************/
1546 /* driver Module init */
1547 /**********************/
1549 hfc4s8s_module_init(void)
1554 "HFC-4S/8S: Layer 1 driver module for HFC-4S/8S isdn chips, %s\n",
1557 "HFC-4S/8S: (C) 2003 Cornelius Consult, www.cornelius-consult.de\n");
1561 err = pci_register_driver(&hfc4s8s_driver);
1565 printk(KERN_INFO "HFC-4S/8S: found %d cards\n", card_cnt);
1570 } /* hfc4s8s_init_hw */
1572 /*************************************/
1573 /* driver module exit : */
1574 /* release the HFC-4s/8s hardware */
1575 /*************************************/
1577 hfc4s8s_module_exit(void)
1579 pci_unregister_driver(&hfc4s8s_driver);
1580 printk(KERN_INFO "HFC-4S/8S: module removed\n");
1581 } /* hfc4s8s_release_hw */
1583 module_init(hfc4s8s_module_init);
1584 module_exit(hfc4s8s_module_exit);