26 #include <linux/module.h>
29 #include <linux/pci.h>
32 #include <linux/slab.h>
34 #include <linux/netdevice.h>
42 #define __debug_variable debug
45 #ifdef CONFIG_HISAX_DEBUG
60 .driver_data = (
unsigned long)
"Fritz!Card PCI",
66 .driver_data = (
unsigned long)
"Fritz!Card PCI v2" },
76 .driver_data = (
unsigned long)
"Fritz!Card PnP",
90 #define AVM_INDEX 0x04
93 #define AVM_IDX_HDLC_1 0x00
94 #define AVM_IDX_HDLC_2 0x01
95 #define AVM_IDX_ISAC_FIFO 0x02
96 #define AVM_IDX_ISAC_REG_LOW 0x04
97 #define AVM_IDX_ISAC_REG_HIGH 0x06
99 #define AVM_STATUS0 0x02
101 #define AVM_STATUS0_IRQ_ISAC 0x01
102 #define AVM_STATUS0_IRQ_HDLC 0x02
103 #define AVM_STATUS0_IRQ_TIMER 0x04
104 #define AVM_STATUS0_IRQ_MASK 0x07
106 #define AVM_STATUS0_RESET 0x01
107 #define AVM_STATUS0_DIS_TIMER 0x02
108 #define AVM_STATUS0_RES_TIMER 0x04
109 #define AVM_STATUS0_ENA_IRQ 0x08
110 #define AVM_STATUS0_TESTBIT 0x10
112 #define AVM_STATUS1 0x03
113 #define AVM_STATUS1_ENA_IOM 0x80
115 #define HDLC_FIFO 0x0
116 #define HDLC_STATUS 0x4
117 #define HDLC_CTRL 0x4
119 #define HDLC_MODE_ITF_FLG 0x01
120 #define HDLC_MODE_TRANS 0x02
121 #define HDLC_MODE_CCR_7 0x04
122 #define HDLC_MODE_CCR_16 0x08
123 #define HDLC_MODE_TESTLOOP 0x80
125 #define HDLC_INT_XPR 0x80
126 #define HDLC_INT_XDU 0x40
127 #define HDLC_INT_RPR 0x20
128 #define HDLC_INT_MASK 0xE0
130 #define HDLC_STAT_RME 0x01
131 #define HDLC_STAT_RDO 0x10
132 #define HDLC_STAT_CRCVFRRAB 0x0E
133 #define HDLC_STAT_CRCVFR 0x06
134 #define HDLC_STAT_RML_MASK 0xff00
136 #define HDLC_CMD_XRS 0x80
137 #define HDLC_CMD_XME 0x01
138 #define HDLC_CMD_RRS 0x20
139 #define HDLC_CMD_XML_MASK 0xff00
141 #define AVM_HDLC_FIFO_1 0x10
142 #define AVM_HDLC_FIFO_2 0x18
144 #define AVM_HDLC_STATUS_1 0x14
145 #define AVM_HDLC_STATUS_2 0x1c
147 #define AVM_ISACSX_INDEX 0x04
148 #define AVM_ISACSX_DATA 0x08
153 static unsigned char fcpci_read_isac(
struct isac *
isac,
unsigned char offset)
156 unsigned char idx = (offset > 0x2f) ?
164 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
165 DBG(0x1000,
" port %#x, value %#x",
170 static void fcpci_write_isac(
struct isac *
isac,
unsigned char offset,
174 unsigned char idx = (offset > 0x2f) ?
178 DBG(0x1000,
" port %#x, value %#x",
183 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
186 static void fcpci_read_isac_fifo(
struct isac *
isac,
unsigned char *
data,
195 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
198 static void fcpci_write_isac_fifo(
struct isac *
isac,
unsigned char *
data,
207 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
219 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
223 static void __fcpci_write_ctrl(
struct fritz_bcs *
bcs,
int which)
228 DBG(0x40,
"hdlc %c wr%x ctrl %x",
235 static void fcpci_write_ctrl(
struct fritz_bcs *
bcs,
int which)
241 __fcpci_write_ctrl(bcs, which);
242 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
248 static unsigned char fcpci2_read_isac(
struct isac *
isac,
unsigned char offset)
257 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
258 DBG(0x1000,
" port %#x, value %#x",
264 static void fcpci2_write_isac(
struct isac *
isac,
unsigned char offset,
270 DBG(0x1000,
" port %#x, value %#x",
275 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
278 static void fcpci2_read_isac_fifo(
struct isac *
isac,
unsigned char *
data,
287 for (i = 0; i <
size; i++)
289 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
292 static void fcpci2_write_isac_fifo(
struct isac *isac,
unsigned char *data,
301 for (i = 0; i <
size; i++)
303 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
310 return inl(adapter->
io + offset);
313 static void fcpci2_write_ctrl(
struct fritz_bcs *
bcs,
int which)
318 DBG(0x40,
"hdlc %c wr%x ctrl %x",
338 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
342 static void __fcpnp_write_ctrl(
struct fritz_bcs *
bcs,
int which)
347 DBG(0x40,
"hdlc %c wr%x ctrl %x",
362 static void fcpnp_write_ctrl(
struct fritz_bcs *bcs,
int which)
368 __fcpnp_write_ctrl(bcs, which);
369 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
374 static inline void B_L1L2(
struct fritz_bcs *bcs,
int pr,
void *
arg)
378 DBG(2,
"pr %#x", pr);
379 ifc->
l1l2(ifc, pr, arg);
382 static void hdlc_fill_fifo(
struct fritz_bcs *bcs)
390 DBG(0x40,
"hdlc_fill_fifo");
402 DBG(0x40,
"hdlc_fill_fifo %d/%d", count, bcs->
tx_skb->len);
408 switch (adapter->
type) {
412 __fcpci_write_ctrl(bcs, 3);
415 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
418 fcpci2_write_ctrl(bcs, 3);
426 __fcpnp_write_ctrl(bcs, 3);
428 spin_unlock_irqrestore(&adapter->
hw_lock, flags);
433 static inline void hdlc_empty_fifo(
struct fritz_bcs *bcs,
int count)
439 DBG(0x10,
"hdlc_empty_fifo %d", count);
441 DBG(0x10,
"hdlc_empty_fifo: incoming packet too large");
446 switch (adapter->
type) {
452 spin_unlock(&adapter->
hw_lock);
463 spin_unlock(&adapter->
hw_lock);
476 bcs->
ctrl.sr.xml = 0;
489 hdlc_empty_fifo(bcs, len);
494 skb = dev_alloc_skb(bcs->
rcvidx);
505 DBG(0x10,
"ch%d invalid frame %#x",
512 static inline void hdlc_xdu_irq(
struct fritz_bcs *bcs)
520 bcs->
ctrl.sr.xml = 0;
526 DBG(0x10,
"XDU without skb");
537 static inline void hdlc_xpr_irq(
struct fritz_bcs *bcs)
555 static void hdlc_irq_one(
struct fritz_bcs *bcs,
u32 stat)
557 DBG(0x10,
"ch%d stat %#x", bcs->
channel, stat);
560 hdlc_rpr_irq(bcs, stat);
579 for (nr = 0; nr < 2; nr++) {
581 DBG(0x10,
"HDLC %c stat %#x",
'A' + nr, stat);
583 hdlc_irq_one(&adapter->
bcs[nr], stat);
591 DBG(0x40,
"hdlc %c mode %d --> %d",
594 if (bcs->
mode == mode)
618 bcs->
ctrl.sr.cmd = 0;
624 static void fritz_b_l2l1(
struct hisax_if *ifc,
int pr,
void *arg)
630 DBG(0x10,
"pr %#x", pr);
641 DBG(4,
"B%d,PH_ACTIVATE_REQUEST %d", bcs->
channel + 1, mode);
646 DBG(4,
"B%d,PH_DEACTIVATE_REQUEST", bcs->
channel + 1);
656 fcpci2_irq(
int intno,
void *
dev)
665 DBG(2,
"STATUS0 %#x", val);
670 if (val & AVM_STATUS0_IRQ_ISAC)
676 fcpci_irq(
int intno,
void *dev)
681 sval =
inb(adapter->
io + 2);
682 if ((sval & AVM_STATUS0_IRQ_MASK) == AVM_STATUS0_IRQ_MASK)
685 DBG(2,
"sval %#x", sval);
686 if (!(sval & AVM_STATUS0_IRQ_ISAC))
689 if (!(sval & AVM_STATUS0_IRQ_HDLC))
696 static inline void fcpci2_init(
struct fritz_adapter *adapter)
728 switch (adapter->
type) {
731 val =
inl(adapter->
io);
734 val =
inb(adapter->
io);
735 val |=
inb(adapter->
io + 1) << 8;
739 DBG(1,
"stat %#x Class %X Rev %d",
740 val, val & 0xff, (val >> 8) & 0xff);
744 switch (adapter->
type) {
746 adapter->
isac.read_isac = &fcpci2_read_isac;
747 adapter->
isac.write_isac = &fcpci2_write_isac;
748 adapter->
isac.read_isac_fifo = &fcpci2_read_isac_fifo;
749 adapter->
isac.write_isac_fifo = &fcpci2_write_isac_fifo;
755 adapter->
isac.read_isac = &fcpci_read_isac;
756 adapter->
isac.write_isac = &fcpci_write_isac;
757 adapter->
isac.read_isac_fifo = &fcpci_read_isac_fifo;
758 adapter->
isac.write_isac_fifo = &fcpci_write_isac_fifo;
764 adapter->
isac.read_isac = &fcpci_read_isac;
765 adapter->
isac.write_isac = &fcpci_write_isac;
766 adapter->
isac.read_isac_fifo = &fcpci_read_isac_fifo;
767 adapter->
isac.write_isac_fifo = &fcpci_write_isac_fifo;
782 switch (adapter->
type) {
785 "fcpcipnp", adapter);
789 "fcpcipnp", adapter);
793 "fcpcipnp", adapter);
799 switch (adapter->
type) {
801 fcpci2_init(adapter);
811 DBG(0x20,
"HDLC A STA %x", val);
813 DBG(0x20,
"HDLC B STA %x", val);
815 adapter->
bcs[0].mode = -1;
816 adapter->
bcs[1].mode = -1;
851 adapter->
isac.hisax_d_if.ifc.priv = &adapter->
isac;
854 for (i = 0; i < 2; i++) {
856 adapter->
bcs[
i].channel =
i;
857 adapter->
bcs[
i].b_if.ifc.priv = &adapter->
bcs[
i];
858 adapter->
bcs[
i].b_if.ifc.l2l1 = fritz_b_l2l1;
861 for (i = 0; i < 2; i++)
862 b_if[i] = &adapter->
bcs[i].b_if;
886 adapter = new_adapter();
890 pci_set_drvdata(pdev, adapter);
907 retval = fcpcipnp_setup(adapter);
914 delete_adapter(adapter);
929 adapter = new_adapter();
933 pnp_set_drvdata(pdev, adapter);
944 adapter->
io = pnp_port_start(pdev, 0);
947 printk(
KERN_INFO "hisax_fcpcipnp: found adapter %s at IO %#x irq %d\n",
950 retval = fcpcipnp_setup(adapter);
957 delete_adapter(adapter);
967 fcpcipnp_release(adapter);
968 delete_adapter(adapter);
975 .probe = fcpnp_probe,
977 .id_table = fcpnp_ids,
985 fcpcipnp_release(adapter);
987 delete_adapter(adapter);
992 .probe = fcpci_probe,
994 .id_table = fcpci_ids,
997 static int __init hisax_fcpcipnp_init(
void)
1001 printk(
KERN_INFO "hisax_fcpcipnp: Fritz!Card PCI/PCIv2/PnP ISDN driver v0.0.1\n");
1003 retval = pci_register_driver(&fcpci_driver);
1016 static void __exit hisax_fcpcipnp_exit(
void)