20 #include <linux/slab.h>
22 static const char *hfcsx_revision =
"$Revision: 1.12.2.5 $";
45 static u_char ccd_sp_irqtab[16] = {
46 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 3, 4, 5, 0, 0, 6
49 static u_char ccd_sp_irqtab[16] = {
50 0, 0, 0, 7, 0, 1, 0, 0, 0, 2, 3, 4, 5, 0, 0, 6
53 #define NT_T1_COUNT 20
55 #define byteout(addr, val) outb(val, addr)
56 #define bytein(addr) inb(addr)
64 byteout(cs->hw.hfcsx.base + 1, regnum);
65 byteout(cs->hw.hfcsx.base, val);
73 byteout(cs->hw.hfcsx.base + 1, regnum);
74 ret =
bytein(cs->hw.hfcsx.base);
83 fifo_select(
struct IsdnCardState *cs,
u_char fifo)
85 if (fifo == cs->hw.hfcsx.last_fifo)
89 byteout(cs->hw.hfcsx.base, fifo);
90 while (
bytein(cs->hw.hfcsx.base + 1) & 1);
92 byteout(cs->hw.hfcsx.base, fifo);
93 while (
bytein(cs->hw.hfcsx.base + 1) & 1);
101 reset_fifo(
struct IsdnCardState *cs,
u_char fifo)
103 fifo_select(cs, fifo);
105 byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.cirm | 0x80);
107 while (
bytein(cs->hw.hfcsx.base + 1) & 1);
117 write_fifo(
struct IsdnCardState *cs,
struct sk_buff *
skb,
u_char fifo,
int trans_max)
123 if (skb->
len <= 0)
return (0);
124 if (fifo & 1)
return (0);
126 fifo_select(cs, fifo);
130 if (trans_max)
return (0);
133 fifo_size = cs->hw.hfcsx.b_fifo_size;
147 if (count < skb->len + 1)
return (0);
148 count = fifo_size -
count;
149 if (count > 2 * trans_max)
return (0);
164 count += (f_msk + 1);
165 if (count > f_msk - 1) {
166 if (cs->debug & L1_DEB_ISAC_FIFO)
167 debugl1(cs,
"hfcsx_write_fifo %d more as %d frames", fifo, f_msk - 1);
173 if (cs->debug & L1_DEB_ISAC_FIFO)
174 debugl1(cs,
"hfcsx_write_fifo %d f1(%x) f2(%x) z1(f1)(%x)",
177 count = *(msp +
f2) - z1;
181 if (cs->debug & L1_DEB_ISAC_FIFO)
182 debugl1(cs,
"hfcsx_write_fifo %d count(%u/%d)",
183 fifo, skb->
len, count);
184 if (count < skb->len) {
185 if (cs->debug & L1_DEB_ISAC_FIFO)
186 debugl1(cs,
"hfcsx_write_fifo %d no fifo mem", fifo);
197 while (
bytein(cs->hw.hfcsx.base + 1) & 1);
207 read_fifo(
struct IsdnCardState *cs,
u_char fifo,
int trans_max)
212 if (!(fifo & 1))
return (
NULL);
213 fifo_select(cs, fifo);
217 if (trans_max)
return (
NULL);
220 fifo_size = cs->hw.hfcsx.b_fifo_size;
235 if (count > trans_max)
237 skb = dev_alloc_skb(count);
251 if (f1 == f2)
return (
NULL);
258 if (cs->debug & L1_DEB_ISAC_FIFO)
259 debugl1(cs,
"hfcsx_read_fifo %d f1(%x) f2(%x) z1(f2)(%x) z2(f2)(%x)",
260 fifo, f1, f2, z1, z2);
267 if (cs->debug & L1_DEB_ISAC_FIFO)
268 debugl1(cs,
"hfcsx_read_fifo %d count %u)",
271 if ((count > fifo_size) || (count < 4)) {
272 if (cs->debug & L1_DEB_WARN)
273 debugl1(cs,
"hfcsx_read_fifo %d paket inv. len %d ", fifo , count);
280 if ((skb = dev_alloc_skb(count - 3))) {
291 if (cs->debug & L1_DEB_ISAC_FIFO)
292 debugl1(cs,
"hfcsx_read_fifo %d crc error", fifo);
302 while (
bytein(cs->hw.hfcsx.base + 1) & 1);
312 release_io_hfcsx(
struct IsdnCardState *cs)
314 cs->hw.hfcsx.int_m2 = 0;
321 kfree(cs->hw.hfcsx.extra);
322 cs->hw.hfcsx.extra =
NULL;
329 static int set_fifo_size(
struct IsdnCardState *cs)
332 if (cs->hw.hfcsx.b_fifo_size)
return (1);
334 if ((cs->hw.hfcsx.chip >> 4) == 9) {
340 cs->hw.hfcsx.cirm |= 0x10;
350 reset_hfcsx(
struct IsdnCardState *cs)
352 cs->hw.hfcsx.int_m2 = 0;
363 cs->hw.hfcsx.last_fifo = 0xff;
364 if (!set_fifo_size(cs))
continue;
374 cs->hw.hfcsx.bswapped = 0;
375 cs->hw.hfcsx.nt_mode = 0;
392 cs->hw.hfcsx.sctrl = 0x40;
394 cs->hw.hfcsx.sctrl_r = 0;
404 cs->hw.hfcsx.conn = 0x36;
421 hfcsx_Timer(
struct IsdnCardState *cs)
423 cs->hw.hfcsx.timer.expires =
jiffies + 75;
435 Sel_BCS(
struct IsdnCardState *cs,
int channel)
437 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
438 return (&cs->bcs[0]);
439 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
440 return (&cs->bcs[1]);
450 receive_dmsg(
struct IsdnCardState *cs)
456 debugl1(cs,
"rec_dmsg blocked");
466 }
while (--count && skb);
476 main_rec_hfcsx(
struct BCState *bcs)
478 struct IsdnCardState *cs = bcs->cs;
485 debugl1(cs,
"rec_data %d blocked", bcs->channel);
488 skb = read_fifo(cs, ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
508 hfcsx_fill_dfifo(
struct IsdnCardState *cs)
512 if (cs->tx_skb->len <= 0)
526 hfcsx_fill_fifo(
struct BCState *bcs)
528 struct IsdnCardState *cs = bcs->cs;
532 if (bcs->tx_skb->len <= 0)
535 if (write_fifo(cs, bcs->tx_skb,
536 ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
541 bcs->tx_cnt -= bcs->tx_skb->len;
542 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
543 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
546 bcs->ackcnt += bcs->tx_skb->len;
547 spin_unlock_irqrestore(&bcs->aclock, flags);
560 dch_nt_l2l1(
struct PStack *
st,
int pr,
void *
arg)
562 struct IsdnCardState *cs = (
struct IsdnCardState *) st->l1.hardware;
568 st->l1.l1hw(st, pr, arg);
575 debugl1(cs,
"PH_TEST_LOOP B1");
577 debugl1(cs,
"PH_TEST_LOOP B2");
578 if (!(3 & (
long) arg))
579 debugl1(cs,
"PH_TEST_LOOP DISABLED");
584 debugl1(cs,
"dch_nt_l2l1 msg %04X unhandled", pr);
595 hfcsx_auxcmd(
struct IsdnCardState *cs,
isdn_ctrl *ic)
598 int i = *(
unsigned int *) ic->
parm.
num;
600 if ((ic->
arg == 98) &&
611 cs->dc.hfcsx.ph_state = 1;
612 cs->hw.hfcsx.nt_mode = 1;
613 cs->hw.hfcsx.nt_timer = 0;
614 spin_unlock_irqrestore(&cs->lock, flags);
615 cs->stlist->l2.l2l1 = dch_nt_l2l1;
616 debugl1(cs,
"NT mode activated");
619 if ((cs->chanlimit > 1) || (cs->hw.hfcsx.bswapped) ||
620 (cs->hw.hfcsx.nt_mode) || (ic->
arg != 12))
625 cs->hw.hfcsx.trm |= 0x20;
630 cs->hw.hfcsx.trm &= ~0x20;
635 cs->hw.hfcsx.conn |= 0x10;
636 cs->hw.hfcsx.ctmt &= ~2;
644 spin_unlock_irqrestore(&cs->lock, flags);
652 receive_emsg(
struct IsdnCardState *cs)
659 debugl1(cs,
"echo_rec_data blocked");
665 if (cs->debug & DEB_DLOG_HEX) {
667 if ((skb->
len) < MAX_DLOG_SPACE / 3 - 10) {
683 }
while (--count && skb);
694 hfcsx_interrupt(
int intno,
void *
dev_id)
696 struct IsdnCardState *cs =
dev_id;
703 if (!(cs->hw.hfcsx.int_m2 & 0x08))
709 if (cs->debug & L1_DEB_ISAC)
710 debugl1(cs,
"HFC-SX: stat(%02x) s1(%02x)", stat, val);
712 spin_unlock_irqrestore(&cs->lock, flags);
715 if (cs->debug & L1_DEB_ISAC)
716 debugl1(cs,
"HFC-SX irq %x %s", val,
717 test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
718 "locked" :
"unlocked");
719 val &= cs->hw.hfcsx.int_m1;
722 if (cs->debug & L1_DEB_ISAC)
723 debugl1(cs,
"ph_state chg %d->%d", cs->dc.hfcsx.ph_state,
725 cs->dc.hfcsx.ph_state = exval;
730 if (cs->hw.hfcsx.nt_mode) {
731 if ((--cs->hw.hfcsx.nt_timer) < 0)
738 if (
test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
739 cs->hw.hfcsx.int_s1 |=
val;
740 spin_unlock_irqrestore(&cs->lock, flags);
743 if (cs->hw.hfcsx.int_s1 & 0x18) {
745 val = cs->hw.hfcsx.int_s1;
746 cs->hw.hfcsx.int_s1 = exval;
749 if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
751 debugl1(cs,
"hfcsx spurious 0x08 IRQ");
758 else if (!(bcs = Sel_BCS(cs, 1))) {
760 debugl1(cs,
"hfcsx spurious 0x10 IRQ");
765 if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
767 debugl1(cs,
"hfcsx spurious 0x01 IRQ");
771 hfcsx_fill_fifo(bcs);
774 debugl1(cs,
"fill_data %d blocked", bcs->channel);
778 hfcsx_fill_fifo(bcs);
781 debugl1(cs,
"fill_data %d blocked", bcs->channel);
789 if (!(bcs = Sel_BCS(cs, 1))) {
791 debugl1(cs,
"hfcsx spurious 0x02 IRQ");
795 hfcsx_fill_fifo(bcs);
798 debugl1(cs,
"fill_data %d blocked", bcs->channel);
802 hfcsx_fill_fifo(bcs);
805 debugl1(cs,
"fill_data %d blocked", bcs->channel);
821 if (cs->tx_skb->len) {
823 hfcsx_fill_dfifo(cs);
826 debugl1(cs,
"hfcsx_fill_dfifo irq blocked");
838 hfcsx_fill_dfifo(cs);
841 debugl1(cs,
"hfcsx_fill_dfifo irq blocked");
847 if (cs->hw.hfcsx.int_s1 && count--) {
848 val = cs->hw.hfcsx.int_s1;
849 cs->hw.hfcsx.int_s1 = 0;
850 if (cs->debug & L1_DEB_ISAC)
851 debugl1(cs,
"HFC-SX irq %x loop %d", val, 15 - count);
855 spin_unlock_irqrestore(&cs->lock, flags);
863 hfcsx_dbusy_timer(
struct IsdnCardState *cs)
871 HFCSX_l1hw(
struct PStack *st,
int pr,
void *arg)
873 struct IsdnCardState *cs = (
struct IsdnCardState *) st->l1.hardware;
879 if (cs->debug & DEB_DLOG_HEX)
881 if (cs->debug & DEB_DLOG_VERBOSE)
887 if (cs->debug & L1_DEB_LAPD)
894 if (cs->debug & L1_DEB_LAPD)
898 hfcsx_fill_dfifo(cs);
901 debugl1(cs,
"hfcsx_fill_dfifo blocked");
904 spin_unlock_irqrestore(&cs->lock, flags);
909 if (cs->debug & L1_DEB_WARN)
910 debugl1(cs,
" l2l1 tx_skb exist this shouldn't happen");
912 spin_unlock_irqrestore(&cs->lock, flags);
915 if (cs->debug & DEB_DLOG_HEX)
917 if (cs->debug & DEB_DLOG_VERBOSE)
922 if (cs->debug & L1_DEB_LAPD)
926 hfcsx_fill_dfifo(cs);
929 debugl1(cs,
"hfcsx_fill_dfifo blocked");
930 spin_unlock_irqrestore(&cs->lock, flags);
934 if (cs->debug & L1_DEB_LAPD)
935 debugl1(cs,
"-> PH_REQUEST_PULL");
951 spin_unlock_irqrestore(&cs->lock, flags);
957 spin_unlock_irqrestore(&cs->lock, flags);
963 spin_unlock_irqrestore(&cs->lock, flags);
969 spin_unlock_irqrestore(&cs->lock, flags);
973 switch ((
long) arg) {
977 cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~7) | 1;
983 cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~0x38) | 0x08;
987 spin_unlock_irqrestore(&cs->lock, flags);
988 if (cs->debug & L1_DEB_WARN)
989 debugl1(cs,
"hfcsx_l1hw loop invalid %4lx", (
unsigned long)arg);
992 cs->hw.hfcsx.trm |= 0x80;
994 spin_unlock_irqrestore(&cs->lock, flags);
997 if (cs->debug & L1_DEB_WARN)
998 debugl1(cs,
"hfcsx_l1hw unknown pr %4x", pr);
1007 setstack_hfcsx(
struct PStack *st,
struct IsdnCardState *cs)
1009 st->l1.l1hw = HFCSX_l1hw;
1016 hfcsx_send_data(
struct BCState *bcs)
1018 struct IsdnCardState *cs = bcs->cs;
1021 hfcsx_fill_fifo(bcs);
1024 debugl1(cs,
"send_data %d blocked", bcs->channel);
1031 mode_hfcsx(
struct BCState *bcs,
int mode,
int bc)
1033 struct IsdnCardState *cs = bcs->cs;
1036 if (cs->debug & L1_DEB_HSCX)
1037 debugl1(cs,
"HFCSX bchannel mode %d bchan %d/%d",
1038 mode, bc, bcs->channel);
1042 if (cs->chanlimit > 1) {
1043 cs->hw.hfcsx.bswapped = 0;
1044 cs->hw.hfcsx.sctrl_e &= ~0x80;
1048 cs->hw.hfcsx.bswapped = 1;
1049 cs->hw.hfcsx.sctrl_e |= 0x80;
1051 cs->hw.hfcsx.bswapped = 0;
1052 cs->hw.hfcsx.sctrl_e &= ~0x80;
1056 cs->hw.hfcsx.bswapped = 0;
1057 cs->hw.hfcsx.sctrl_e &= ~0x80;
1085 cs->hw.hfcsx.ctmt |= 2;
1086 cs->hw.hfcsx.conn &= ~0x18;
1089 cs->hw.hfcsx.ctmt |= 1;
1090 cs->hw.hfcsx.conn &= ~0x03;
1103 cs->hw.hfcsx.ctmt &= ~2;
1104 cs->hw.hfcsx.conn &= ~0x18;
1107 cs->hw.hfcsx.ctmt &= ~1;
1108 cs->hw.hfcsx.conn &= ~0x03;
1113 cs->hw.hfcsx.conn |= 0x10;
1118 cs->hw.hfcsx.conn |= 0x02;
1141 hfcsx_l2l1(
struct PStack *st,
int pr,
void *arg)
1143 struct BCState *bcs = st->l1.bcs;
1155 bcs->cs->BC_Send_Data(bcs);
1157 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1166 bcs->cs->BC_Send_Data(bcs);
1168 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1180 mode_hfcsx(bcs, st->l1.mode, st->l1.bc);
1181 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1191 mode_hfcsx(bcs, 0, st->l1.bc);
1192 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1202 close_hfcsx(
struct BCState *bcs)
1204 mode_hfcsx(bcs, 0, bcs->channel);
1220 open_hfcsxstate(
struct IsdnCardState *cs,
struct BCState *bcs)
1223 skb_queue_head_init(&bcs->rqueue);
1224 skb_queue_head_init(&bcs->squeue);
1237 setstack_2b(
struct PStack *st,
struct BCState *bcs)
1239 bcs->channel = st->l1.bc;
1240 if (open_hfcsxstate(st->l1.hardware, bcs))
1243 st->l2.l2l1 = hfcsx_l2l1;
1256 struct IsdnCardState *cs =
1261 if (!cs->hw.hfcsx.nt_mode)
1262 switch (cs->dc.hfcsx.ph_state) {
1281 switch (cs->dc.hfcsx.ph_state) {
1284 if (cs->hw.hfcsx.nt_timer < 0) {
1285 cs->hw.hfcsx.nt_timer = 0;
1294 cs->dc.hfcsx.ph_state = 4;
1305 spin_unlock_irqrestore(&cs->lock, flags);
1311 cs->hw.hfcsx.nt_timer = 0;
1314 spin_unlock_irqrestore(&cs->lock, flags);
1331 static void inithfcsx(
struct IsdnCardState *cs)
1333 cs->setstack_d = setstack_hfcsx;
1334 cs->BC_Send_Data = &hfcsx_send_data;
1335 cs->bcs[0].BC_SetStack = setstack_2b;
1336 cs->bcs[1].BC_SetStack = setstack_2b;
1337 cs->bcs[0].BC_Close = close_hfcsx;
1338 cs->bcs[1].BC_Close = close_hfcsx;
1339 mode_hfcsx(cs->bcs, 0, 0);
1340 mode_hfcsx(cs->bcs + 1, 0, 1);
1349 hfcsx_card_msg(
struct IsdnCardState *cs,
int mt,
void *arg)
1353 if (cs->debug & L1_DEB_ISAC)
1354 debugl1(cs,
"HFCSX: card_msg %x", mt);
1359 spin_unlock_irqrestore(&cs->lock, flags);
1362 release_io_hfcsx(cs);
1367 spin_unlock_irqrestore(&cs->lock, flags);
1375 spin_unlock_irqrestore(&cs->lock, flags);
1387 (
unsigned long)
"Teles 16.3c2" },
1398 struct IsdnCardState *cs = card->
cs;
1401 strcpy(tmp, hfcsx_revision);
1406 while (ipid->card_vendor) {
1408 ipid->card_device, pnp_c))) {
1411 ipid->vendor, ipid->function, pnp_d))) {
1415 (
char *)ipid->driver_data);
1423 card->
para[1] = pnp_port_start(pnp_d, 0);
1425 if (!card->
para[0] || !card->
para[1]) {
1439 if (!ipid->card_vendor) {
1445 cs->hw.hfcsx.base = card->
para[1] & 0xfffe;
1446 cs->irq = card->
para[0];
1447 cs->hw.hfcsx.int_s1 = 0;
1448 cs->dc.hfcsx.ph_state = 0;
1449 cs->hw.hfcsx.fifo = 255;
1452 if ((!cs->hw.hfcsx.base) || !
request_region(cs->hw.hfcsx.base, 2,
"HFCSX isdn")) {
1454 "HiSax: HFC-SX io-base %#lx already in use\n",
1458 byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.base & 0xFF);
1459 byteout(cs->hw.hfcsx.base + 1,
1460 ((cs->hw.hfcsx.base >> 8) & 3) | 0x54);
1463 switch (cs->hw.hfcsx.chip >> 4) {
1472 "HFC-SX: invalid chip id 0x%x\n",
1473 cs->hw.hfcsx.chip >> 4);
1477 if (!ccd_sp_irqtab[cs->irq & 0xF]) {
1479 "HFC_SX: invalid irq %d specified\n", cs->irq & 0xF);
1483 if (!(cs->hw.hfcsx.extra = (
void *)
1490 tmp[0], (
u_int) cs->hw.hfcsx.base, cs->irq,
HZ);
1491 cs->hw.hfcsx.int_m2 = 0;
1492 cs->hw.hfcsx.int_m1 = 0;
1498 cs->dbusytimer.function = (
void *) hfcsx_dbusy_timer;
1499 cs->dbusytimer.data = (
long) cs;
1502 cs->readisac =
NULL;
1503 cs->writeisac =
NULL;
1504 cs->readisacfifo =
NULL;
1505 cs->writeisacfifo =
NULL;
1506 cs->BC_Read_Reg =
NULL;
1507 cs->BC_Write_Reg =
NULL;
1508 cs->irq_func = &hfcsx_interrupt;
1510 cs->hw.hfcsx.timer.function = (
void *) hfcsx_Timer;
1511 cs->hw.hfcsx.timer.data = (
long) cs;
1512 cs->hw.hfcsx.b_fifo_size = 0;
1513 cs->hw.hfcsx.cirm = ccd_sp_irqtab[cs->irq & 0xF];
1517 cs->cardmsg = &hfcsx_card_msg;
1518 cs->auxcmd = &hfcsx_auxcmd;