23 #include <linux/module.h>
25 #include <linux/pci.h>
28 #include <linux/slab.h>
31 #include <linux/wait.h>
36 static const char hfc4s8s_rev[] =
"Revision: 1.10";
51 #define TRANS_FIFO_THRES 5
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
72 #define L1_TIMER_T3 (7 * HZ)
73 #define L1_TIMER_T1 ((120 * HZ) / 1000)
96 "HFC-4S Evaluation Board"}),
104 "HFC-8S Evaluation Board"}),
203 #ifdef HISAX_HFC4S8S_PCIMEM
206 #define Write_hfc8(a, b, c) {(*((volatile u_char *)(a->membase + b)) = c); inb(a->iobase + 4);}
208 #define fWrite_hfc8(a, b, c) (*((volatile u_char *)(a->membase + b)) = c)
209 #define Read_hfc8(a, b) (*((volatile u_char *)(a->membase + b)))
210 #define Write_hfc16(a, b, c) (*((volatile unsigned short *)(a->membase + b)) = c)
211 #define Read_hfc16(a, b) (*((volatile unsigned short *)(a->membase + b)))
212 #define Write_hfc32(a, b, c) (*((volatile unsigned long *)(a->membase + b)) = c)
213 #define Read_hfc32(a, b) (*((volatile unsigned long *)(a->membase + b)))
214 #define wait_busy(a) {while ((Read_hfc8(a, R_STATUS) & M_BUSY));}
215 #define PCI_ENA_MEMIO 0x03
307 #define PCI_ENA_REGIO 0x01
320 ref8 = Read_hfc8(hw, reg);
321 while (((in8 = Read_hfc8(hw, reg)) != ref8)) {
333 ref16 = Read_hfc16(hw, reg);
334 while (((in16 = Read_hfc16(hw, reg)) != ref16)) {
361 l1->
hw->mr.r_irq_fifo_blx[l1->
st_num] |=
363 spin_unlock_irqrestore(&l1->
lock, flags);
366 spin_unlock_irqrestore(&l1->
lock, flags);
383 spin_unlock_irqrestore(&l1->
lock,
398 spin_unlock_irqrestore(&l1->
lock,
410 "HFC-4S/8S: Unknown D-chan cmd 0x%x received, ignored\n",
423 bch_l2l1(
struct hisax_if *ifc,
int pr,
void *arg)
441 l1->
hw->mr.r_irq_fifo_blx[l1->
st_num] |=
442 ((bch->
bchan == 1) ? 1 : 4);
443 spin_unlock_irqrestore(&l1->
lock, flags);
446 spin_unlock_irqrestore(&l1->
lock, flags);
460 l1->
hw->mr.timer_usg_cnt++;
462 fifo_slow_timer_service[l1->
490 l1->
hw->mr.r_ctrl0 |=
495 spin_unlock_irqrestore(&l1->
lock,
508 fifo_rx_trans_enables[l1->
513 l1->
hw->mr.timer_usg_cnt++;
537 l1->
hw->mr.r_ctrl0 |=
542 spin_unlock_irqrestore(&l1->
lock,
557 fifo_slow_timer_service[l1->
563 fifo_rx_trans_enables[l1->
568 l1->
hw->mr.timer_usg_cnt--;
584 l1->
hw->mr.r_ctrl0 &=
588 spin_unlock_irqrestore(&l1->
lock,
597 dev_kfree_skb(bch->
tx_skb);
601 dev_kfree_skb(bch->
rx_skb);
612 if (l1->
hw->mr.timer_usg_cnt) {
623 "HFC-4S/8S: Unknown B-chan cmd 0x%x received, ignored\n",
648 spin_unlock_irqrestore(&l1->
lock, flags);
654 spin_unlock_irqrestore(&l1->
lock, flags);
659 spin_unlock_irqrestore(&l1->
lock, flags);
665 spin_unlock_irqrestore(&l1->
lock, flags);
686 (l1p->
st_num * 8 + ((ech) ? 7 : 5)));
689 f1 = Read_hfc8_stable(l1p->
hw,
A_F1);
690 f2 = Read_hfc8(l1p->
hw,
A_F2);
700 z1 = Read_hfc16_stable(l1p->
hw,
A_Z1);
701 z2 = Read_hfc16(l1p->
hw,
A_Z2);
709 "HFC-4S/8S: Could not allocate D/E "
710 "channel receive buffer");
728 #ifndef HISAX_HFC4S8S_PCIMEM
733 #ifdef HISAX_HFC4S8S_PCIMEM
736 fRead_hfc32(l1p->
hw);
742 #ifdef HISAX_HFC4S8S_PCIMEM
756 #ifndef HISAX_HFC4S8S_PCIMEM
761 #ifdef HISAX_HFC4S8S_PCIMEM
762 *((
unsigned long *) cp) =
765 *((
unsigned long *) cp) = fRead_hfc32(l1p->
hw);
772 #ifdef HISAX_HFC4S8S_PCIMEM
775 *cp++ = fRead_hfc8(l1p->
hw);
784 skb->
len = (cp - skb->
data) - 2;
803 int z1, z2, hdlc_complete;
818 f1 = Read_hfc8_stable(l1->
hw,
A_F1);
819 f2 = Read_hfc8(l1->
hw,
A_F2);
820 hdlc_complete = ((f1 ^
f2) & MAX_F_CNT);
823 z1 = Read_hfc16_stable(l1->
hw,
A_Z1);
824 z2 = Read_hfc16(l1->
hw,
A_Z2);
834 if (!(skb = bch->
rx_skb)) {
837 dev_alloc_skb((bch->
mode ==
841 "HFC-4S/8S: Could not allocate B "
842 "channel receive buffer");
853 ((hdlc_complete && (skb->
len < 4)) ||
862 #ifndef HISAX_HFC4S8S_PCIMEM
867 #ifdef HISAX_HFC4S8S_PCIMEM
868 *((
unsigned long *) bch->
rx_ptr) =
871 *((
unsigned long *) bch->
rx_ptr) =
879 #ifdef HISAX_HFC4S8S_PCIMEM
882 *(bch->
rx_ptr++) = fRead_hfc8(l1->
hw);
927 f1 = Read_hfc8(l1p->
hw,
A_F1);
928 f2 = Read_hfc8_stable(l1p->
hw,
A_F2);
930 if ((f1 ^ f2) & MAX_F_CNT)
943 #ifndef HISAX_HFC4S8S_PCIMEM
948 #ifdef HISAX_HFC4S8S_PCIMEM
950 *(
unsigned long *) cp);
953 fWrite_hfc32(l1p->
hw, *(
unsigned long *) cp);
959 #ifdef HISAX_HFC4S8S_PCIMEM
964 fWrite_hfc8(l1p->
hw, *cp++);
1007 if (!(skb = bch->
tx_skb)) {
1009 l1->
hw->mr.fifo_slow_timer_service[l1->
1011 &= ~((bch->
bchan == 1) ? 1 : 4);
1019 l1->
hw->mr.fifo_slow_timer_service[l1->
st_num] |=
1020 ((bch->
bchan == 1) ? 1 : 4);
1022 l1->
hw->mr.fifo_slow_timer_service[l1->
st_num] &=
1023 ~((bch->
bchan == 1) ? 1 : 4);
1025 max = Read_hfc16_stable(l1->
hw,
A_Z2);
1026 max -= Read_hfc16(l1->
hw,
A_Z1);
1040 #ifndef HISAX_HFC4S8S_PCIMEM
1044 #ifdef HISAX_HFC4S8S_PCIMEM
1046 *(
unsigned long *) cp);
1048 fWrite_hfc32(l1->
hw, *(
unsigned long *) cp);
1055 #ifdef HISAX_HFC4S8S_PCIMEM
1058 fWrite_hfc8(l1->
hw, *cp++);
1074 ((bch->
bchan == 1) ? 0 : 2)));
1092 volatile u_char *fifo_stat;
1099 if ((b & hw->
mr.r_irq_statech)) {
1101 hw->
mr.r_irq_statech &= ~b;
1114 l1p->
d_if.ifc.l1l2(&l1p->
1142 "HFC-4S/8S: NT ch %d l1 state %d -> %d\n",
1156 (oldstate == 8))) ||
1191 "HFC-4S/8S: TE %d ch %d l1 state %d -> %d\n",
1204 fifo_stat = hw->
mr.r_irq_fifo_blx;
1208 if (hw->
mr.timer_irq) {
1209 *fifo_stat |= hw->
mr.fifo_rx_trans_enables[
idx];
1212 hw->
mr.fifo_slow_timer_service[l1p->
1217 *fifo_stat &= 0xff - 0x40;
1219 while (*fifo_stat) {
1223 if ((*fifo_stat & 0x20)) {
1224 *fifo_stat &= ~0x20;
1228 if ((*fifo_stat & 0x80)) {
1229 *fifo_stat &= ~0x80;
1233 if ((*fifo_stat & 0x10)) {
1234 *fifo_stat &= ~0x10;
1239 if ((*fifo_stat & 0x2)) {
1241 rx_b_frame(l1p->
b_ch);
1244 if ((*fifo_stat & 0x1)) {
1246 tx_b_frame(l1p->
b_ch);
1249 if ((*fifo_stat & 0x8)) {
1251 rx_b_frame(l1p->
b_ch + 1);
1254 if ((*fifo_stat & 0x4)) {
1256 tx_b_frame(l1p->
b_ch + 1);
1266 hw->
mr.timer_irq = 0;
1273 hfc4s8s_interrupt(
int intno,
void *
dev_id)
1284 #ifndef HISAX_HFC4S8S_PCIMEM
1286 old_ioreg = GetRegAddr(hw);
1290 hw->
mr.r_irq_statech |=
1291 (Read_hfc8(hw,
R_SCI) & hw->
mr.r_irqmsk_statchg);
1294 && !hw->
mr.r_irq_statech) {
1295 #ifndef HISAX_HFC4S8S_PCIMEM
1296 SetRegAddr(hw, old_ioreg);
1303 hw->
mr.timer_irq = 1;
1309 hw->
mr.r_irq_oview |= ovr;
1311 ovp = hw->
mr.r_irq_fifo_blx;
1314 *ovp |= Read_hfc8(hw, idx);
1325 #ifndef HISAX_HFC4S8S_PCIMEM
1326 SetRegAddr(hw, old_ioreg);
1340 Write_hfc8(hw,
R_CTRL, 0);
1344 hw->
mr.r_irq_ctrl = 0;
1345 spin_unlock_irqrestore(&hw->
lock, flags);
1348 Write_hfc8(hw,
R_CIRM, 0);
1377 hw->
mr.r_irqmsk_statchg = 0;
1378 Write_hfc8(hw,
R_SCI_MSK, hw->
mr.r_irqmsk_statchg);
1380 Write_hfc8(hw,
R_PWM1, 26);
1386 hw->
mr.r_irqmsk_statchg |= (1 <<
i);
1387 Write_hfc8(hw,
R_SCI_MSK, hw->
mr.r_irqmsk_statchg);
1396 hw->
l1[
i].enabled = 1;
1401 Write_hfc8(hw,
R_FIFO, i * 8 + 7);
1410 Write_hfc8(hw,
R_FIFO, i * 8 + 5);
1419 Write_hfc8(hw,
R_FIFO, i * 8 + 4);
1431 (&hw->
l1[i].d_if, hw->
l1[i].b_table, if_name,
1432 ((nt_mode) ? 3 : 2))) {
1434 hw->
l1[
i].enabled = 0;
1435 hw->
mr.r_irqmsk_statchg &= ~(1 <<
i);
1437 hw->
mr.r_irqmsk_statchg);
1439 "HFC-4S/8S: Unable to register S/T device %s, break\n",
1447 spin_unlock_irqrestore(&hw->
lock, flags);
1453 spin_unlock_irqrestore(&hw->
lock, flags);
1456 hw->
l1[
i].enabled = 0;
1474 #ifdef HISAX_HFC4S8S_PCIMEM
1489 #ifdef HISAX_HFC4S8S_PCIMEM
1512 l1p->
l1_timer.function = (
void *) hfc_l1_timer;
1517 l1p->
d_if.ifc.priv = hw->
l1 +
i;
1518 l1p->
d_if.ifc.l2l1 = (
void *) dch_l2l1;
1521 l1p->
b_ch[0].b_if.ifc.l2l1 = (
void *) bch_l2l1;
1522 l1p->
b_ch[0].b_if.ifc.priv = (
void *) &l1p->
b_ch[0];
1523 l1p->
b_ch[0].l1p = hw->
l1 + i;
1524 l1p->
b_ch[0].bchan = 1;
1526 skb_queue_head_init(&l1p->
b_ch[0].tx_queue);
1529 l1p->
b_ch[1].b_if.ifc.l2l1 = (
void *) bch_l2l1;
1530 l1p->
b_ch[1].b_if.ifc.priv = (
void *) &l1p->
b_ch[1];
1531 l1p->
b_ch[1].l1p = hw->
l1 + i;
1532 l1p->
b_ch[1].bchan = 2;
1534 skb_queue_head_init(&l1p->
b_ch[1].tx_queue);
1537 enable_pci_ports(hw);
1543 "HFC-4S/8S: invalid chip id 0x%x instead of 0x%x, card ignored\n",
1551 "HFC-4S/8S: chip revision 0 not supported, card ignored\n");
1560 "HFC-4S/8S: unable to alloc irq %d, card ignored\n",
1564 #ifdef HISAX_HFC4S8S_PCIMEM
1566 "HFC-4S/8S: found PCI card at membase 0x%p, irq %d\n",
1570 "HFC-4S/8S: found PCI card at iobase 0x%x, irq %d\n",
1574 hfc_hardware_enable(hw, 1, 0);
1580 release_pci_ports(hw);
1617 #ifdef HISAX_HFC4S8S_PCIMEM
1623 "HFC-4S/8S: failed to rquest address space at 0x%04x\n",
1629 pci_set_drvdata(pdev, hw);
1630 err = setup_instance(hw);
1644 hfc4s8s_remove(
struct pci_dev *pdev)
1649 hfc_hardware_enable(hw, 0, 0);
1654 release_pci_ports(hw);
1663 .name =
"hfc4s8s_l1",
1664 .probe = hfc4s8s_probe,
1666 .id_table = hfc4s8s_ids,
1673 hfc4s8s_module_init(
void)
1678 "HFC-4S/8S: Layer 1 driver module for HFC-4S/8S isdn chips, %s\n",
1681 "HFC-4S/8S: (C) 2003 Cornelius Consult, www.cornelius-consult.de\n");
1685 err = pci_register_driver(&hfc4s8s_driver);
1691 #if !defined(CONFIG_HOTPLUG)
1709 hfc4s8s_module_exit(
void)