24 #include <linux/slab.h>
25 #include <linux/module.h>
30 #define DBUSY_TIMER_VALUE 80
33 #define ISAC_REV "2.0"
39 #define ReadISAC(is, o) (is->read_reg(is->dch.hw, o + is->off))
40 #define WriteISAC(is, o, v) (is->write_reg(is->dch.hw, o + is->off, v))
41 #define ReadHSCX(h, o) (h->ip->read_reg(h->ip->hw, h->off + o))
42 #define WriteHSCX(h, o, v) (h->ip->write_reg(h->ip->hw, h->off + o, v))
43 #define ReadIPAC(ip, o) (ip->read_reg(ip->hw, o))
44 #define WriteIPAC(ip, o, v) (ip->write_reg(ip->hw, o, v))
59 switch (isac->
state) {
68 isac_ph_state_bh(
struct dchannel *dch)
72 switch (isac->
state) {
91 if (dch->
state <= 5) {
122 if (!isac->
dch.rx_skb) {
124 if (!isac->
dch.rx_skb) {
125 pr_info(
"%s: D receive out of memory\n", isac->
name);
130 if ((isac->
dch.rx_skb->len + count) >= isac->
dch.maxlen) {
132 isac->
dch.rx_skb->len + count);
149 isac_fill_fifo(
struct isac_hw *isac)
154 if (!isac->
dch.tx_skb)
156 count = isac->
dch.tx_skb->len - isac->
dch.tx_idx;
166 ptr = isac->
dch.tx_skb->data + isac->
dch.tx_idx;
171 pr_debug(
"%s: %s dbusytimer running\n", isac->
name, __func__);
187 isac_rme_irq(
struct isac_hw *isac)
192 if ((val & 0x70) != 0x20) {
195 #ifdef ERROR_STATISTIC
201 #ifdef ERROR_STATISTIC
206 if (isac->
dch.rx_skb)
207 dev_kfree_skb(isac->
dch.rx_skb);
219 isac_xpr_irq(
struct isac_hw *isac)
223 if (isac->
dch.tx_skb && isac->
dch.tx_idx < isac->
dch.tx_skb->len) {
224 isac_fill_fifo(isac);
226 if (isac->
dch.tx_skb)
227 dev_kfree_skb(isac->
dch.tx_skb);
229 isac_fill_fifo(isac);
234 isac_retransmit(
struct isac_hw *isac)
240 isac->
dch.tx_idx = 0;
241 isac_fill_fifo(isac);
242 }
else if (isac->
dch.tx_skb) {
243 pr_info(
"%s: tx_skb exist but not busy\n", isac->
name);
245 isac->
dch.tx_idx = 0;
246 isac_fill_fifo(isac);
250 isac_fill_fifo(isac);
255 isac_mos_irq(
struct isac_hw *isac)
267 pr_info(
"%s: ISAC MON RX out of memory!\n",
297 pr_info(
"%s: ISAC MON RX out of memory!\n",
332 pr_info(
"%s: MONITOR 0 received %d but no user\n",
350 pr_info(
"%s: MONITOR 1 received %d but no user\n",
428 isac_cisq_irq(
struct isac_hw *isac) {
435 isac->
state, (val >> 2) & 0xf);
436 isac->
state = (val >> 2) & 0xf;
437 isac_ph_state_change(isac);
446 isacsx_cic_irq(
struct isac_hw *isac)
454 isac->
state, val >> 4);
455 isac->
state = val >> 4;
456 isac_ph_state_change(isac);
461 isacsx_rme_irq(
struct isac_hw *isac)
473 #ifdef ERROR_STATISTIC
480 if (isac->
dch.rx_skb)
481 dev_kfree_skb(isac->
dch.rx_skb);
488 if (isac->
dch.rx_skb) {
491 isac->
dch.rx_skb->len);
505 isacsx_cic_irq(isac);
511 #ifdef ERROR_STATISTIC
514 isac_retransmit(isac);
518 #ifdef ERROR_STATISTIC
521 isac_retransmit(isac);
530 isacsx_rme_irq(isac);
554 #ifdef ERROR_STATISTIC
557 isac_retransmit(isac);
568 isac_l1hw(
struct mISDNchannel *ch,
struct sk_buff *
skb)
584 isac_fill_fifo(isac);
586 spin_unlock_irqrestore(isac->
hwlock, flags);
589 spin_unlock_irqrestore(isac->
hwlock, flags);
628 spin_unlock_irqrestore(isac->
hwlock, flags);
635 __func__, cmd, para);
652 spin_unlock_irqrestore(isac->
hwlock, flags);
657 spin_unlock_irqrestore(isac->
hwlock, flags);
667 spin_unlock_irqrestore(isac->
hwlock, flags);
672 dev_kfree_skb(dch->
tx_skb);
677 dev_kfree_skb(dch->
rx_skb);
687 spin_unlock_irqrestore(isac->
hwlock, flags);
708 isac_release(
struct isac_hw *isac)
714 if (isac->
dch.timer.function !=
NULL) {
716 isac->
dch.timer.function =
NULL;
728 dbusy_timer_handler(
struct isac_hw *isac)
737 pr_debug(
"%s: D-Channel Busy RBCH %02x STAR %02x\n",
738 isac->
name, rbch, star);
744 if (isac->
dch.tx_idx)
745 isac->
dch.tx_idx = 0;
747 pr_info(
"%s: ISAC D-Channel Busy no tx_idx\n",
752 spin_unlock_irqrestore(isac->
hwlock, flags);
757 open_dchannel(
struct isac_hw *isac,
struct channel_req *
rq)
759 pr_debug(
"%s: %s dev(%d) open from %p\n", isac->
name, __func__,
760 isac->
dch.dev.id, __builtin_return_address(1));
763 if (rq->adr.channel == 1)
766 rq->ch = &isac->
dch.dev.D;
767 rq->ch->protocol = rq->protocol;
768 if (isac->
dch.state == 7)
774 static const char *ISACVer[] =
775 {
"2086/2186 V1.1",
"2085 B1",
"2085 B2",
779 isac_init(
struct isac_hw *isac)
791 isac->
dch.timer.function = (
void *) dbusy_timer_handler;
792 isac->
dch.timer.data = (
long)isac;
814 isac->
name, val & 0x3f);
817 isac->
state = val >> 4;
818 isac_ph_state_change(isac);
839 val, ISACVer[(val >> 5) & 3]);
840 isac->
type |= ((val >> 5) & 3);
843 if (!(isac->
adf2 & 0x80)) {
844 pr_info(
"%s: only support IOM2 mode but adf2=%02x\n",
858 isac->
state = (val >> 2) & 0xf;
859 isac_ph_state_change(isac);
871 isac->
dch.dev.D.send = isac_l1hw;
872 isac->
init = isac_init;
874 isac->
ctrl = isac_ctrl;
875 isac->
open = open_dchannel;
877 isac->
dch.dev.nrbchan = 2;
898 pr_info(
"%s: B%1d CEC timeout\n", hx->
ip->name, hx->
bch.nr);
909 if ((starb & 0x44) == 0x40)
918 pr_info(
"%s: B%1d XFW timeout\n", hx->
ip->name, hx->
bch.nr);
933 hscx_empty_fifo(
struct hscx_hw *hscx,
u8 count)
938 pr_debug(
"%s: B%1d %d\n", hscx->
ip->name, hscx->
bch.nr, count);
941 hscx_cmdr(hscx, 0x80);
946 hscx_cmdr(hscx, 0x80);
947 if (hscx->
bch.rx_skb)
949 pr_warning(
"%s.B%d: No bufferspace for %d bytes\n",
950 hscx->
ip->name, hscx->
bch.nr, count);
956 hscx->
ip->read_fifo(hscx->
ip->hw,
959 hscx->
ip->read_fifo(hscx->
ip->hw,
960 hscx->
off, p, count);
962 hscx_cmdr(hscx, 0x80);
966 hscx->
bch.nr, hscx->
ip->name, count);
972 hscx_fill_fifo(
struct hscx_hw *hscx)
977 if (!hscx->
bch.tx_skb) {
985 count = hscx->
bch.tx_skb->len - hscx->
bch.tx_idx;
988 p = hscx->
bch.tx_skb->data + hscx->
bch.tx_idx;
995 pr_debug(
"%s: B%1d %d/%d/%d\n", hscx->
ip->name, hscx->
bch.nr,
996 count, hscx->
bch.tx_idx, hscx->
bch.tx_skb->len);
1000 hscx->
ip->write_fifo(hscx->
ip->hw,
1004 hscx->
ip->write_fifo(hscx->
ip->hw,
1005 hscx->
off, p, count);
1007 hscx_cmdr(hscx, more ? 0x08 : 0x0a);
1011 hscx->
bch.nr, hscx->
ip->name, count);
1019 if (hx->
bch.tx_skb && hx->
bch.tx_idx < hx->
bch.tx_skb->len) {
1023 dev_kfree_skb(hx->
bch.tx_skb);
1043 pr_debug(
"%s: B%1d RSTAB %02x\n", hx->
ip->name, hx->
bch.nr, rstab);
1044 if ((rstab & 0xf0) != 0xa0) {
1046 if (!(rstab & 0x80)) {
1049 hx->
ip->name, hx->
bch.nr);
1054 hx->
ip->name, hx->
bch.nr,
1057 if (!(rstab & 0x20)) {
1060 hx->
ip->name, hx->
bch.nr);
1062 hscx_cmdr(hx, 0x80);
1072 hscx_empty_fifo(hx, count);
1073 if (!hx->
bch.rx_skb)
1075 if (hx->
bch.rx_skb->len < 2) {
1076 pr_debug(
"%s: B%1d frame to short %d\n",
1077 hx->
ip->name, hx->
bch.nr, hx->
bch.rx_skb->len);
1088 u8 istab,
m, exirb = 0;
1097 pr_debug(
"%s: B%1d EXIRB %02x\n", hx->
ip->name,
1100 }
else if (hx->
bch.nr & 2) {
1102 ipac_irq(&hx->
ip->hscx[0], ista);
1105 pr_debug(
"%s: B%1d EXIRB %02x\n", hx->
ip->name,
1108 istab = ista & 0xF8;
1113 pr_debug(
"%s: B%1d EXIRB %02x\n", hx->
ip->name,
1116 istab = istab & 0xF8;
1122 pr_debug(
"%s: B%1d ISTAB %02x\n", hx->
ip->name, hx->
bch.nr, istab);
1138 hscx_cmdr(hx, 0x40);
1151 pr_debug(
"%s: B%1d XDU error at len %d\n", hx->
ip->name,
1152 hx->
bch.nr, hx->
bch.tx_idx);
1154 hscx_cmdr(hx, 0x01);
1161 int cnt = maxloop + 1;
1167 while (ista && cnt--) {
1170 ipac_irq(&ipac->
hscx[0], ista);
1172 ipac_irq(&ipac->
hscx[1], ista);
1179 while (ista && cnt--) {
1191 ipac_irq(&ipac->
hscx[0], ista);
1193 ipac_irq(&ipac->
hscx[1], ista);
1201 ipac_irq(&ipac->
hscx[1], ista);
1206 if (0 == (ista | istad))
1216 if (maxloop && !cnt)
1224 hscx_mode(
struct hscx_hw *hscx,
u32 bprotocol)
1226 pr_debug(
"%s: HSCX %c protocol %x-->%x ch %d\n", hscx->
ip->name,
1227 '@' + hscx->
bch.nr, hscx->
bch.state, bprotocol, hscx->
bch.nr);
1229 if (hscx->
bch.nr & 1) {
1236 switch (bprotocol) {
1241 hscx_cmdr(hscx, 0x41);
1248 hscx_cmdr(hscx, 0x41);
1255 hscx_cmdr(hscx, 0x41);
1260 pr_info(
"%s: protocol not known %x\n", hscx->
ip->name,
1271 switch (bprotocol) {
1284 hscx_cmdr(hscx, 0x41);
1291 hscx_cmdr(hscx, 0x41);
1296 pr_info(
"%s: protocol not known %x\n", hscx->
ip->name,
1307 switch (bprotocol) {
1320 hscx_cmdr(hscx, 0x41);
1327 hscx_cmdr(hscx, 0x41);
1332 pr_info(
"%s: protocol not known %x\n", hscx->
ip->name,
1338 hscx->
bch.state = bprotocol;
1343 hscx_l2l1(
struct mISDNchannel *ch,
struct sk_buff *skb)
1348 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1349 unsigned long flags;
1359 spin_unlock_irqrestore(hx->
ip->hwlock, flags);
1364 ret = hscx_mode(hx, ch->protocol);
1367 spin_unlock_irqrestore(hx->
ip->hwlock, flags);
1376 spin_unlock_irqrestore(hx->
ip->hwlock, flags);
1382 pr_info(
"%s: %s unknown prim(%x,%x)\n",
1383 hx->
ip->name, __func__, hh->
prim, hh->
id);
1398 hscx_bctrl(
struct mISDNchannel *ch,
u32 cmd,
void *
arg)
1405 pr_debug(
"%s: %s cmd:%x %p\n", hx->
ip->name, __func__, cmd, arg);
1413 spin_unlock_irqrestore(hx->
ip->hwlock, flags);
1416 module_put(hx->
ip->owner);
1420 ret = channel_bctrl(bch, arg);
1423 pr_info(
"%s: %s unknown prim(%x)\n",
1424 hx->
ip->name, __func__, cmd);
1430 free_ipac(
struct ipac_hw *ipac)
1432 isac_release(&ipac->
isac);
1435 static const char *HSCXVer[] =
1436 {
"A1",
"?1",
"A2",
"?3",
"A3",
"V2.1",
"?6",
"?7",
1437 "?8",
"?9",
"?10",
"?11",
"?12",
"?13",
"?14",
"???"};
1453 pr_debug(
"%s: HSCX VSTR %02x\n", hx->
ip->name, val);
1456 HSCXVer[val & 0x0f]);
1465 ipac_init(
struct ipac_hw *ipac)
1470 hscx_init(&ipac->
hscx[0]);
1471 hscx_init(&ipac->
hscx[1]);
1474 hscx_init(&ipac->
hscx[0]);
1475 hscx_init(&ipac->
hscx[1]);
1487 return isac_init(&ipac->
isac);
1491 open_bchannel(
struct ipac_hw *ipac,
struct channel_req *rq)
1495 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1499 bch = &ipac->
hscx[rq->adr.channel - 1].bch;
1503 bch->
ch.protocol = rq->protocol;
1537 ipac_dctrl(
struct mISDNchannel *ch,
u32 cmd,
void *arg)
1539 struct mISDNdevice *dev =
container_of(ch,
struct mISDNdevice,
D);
1543 struct channel_req *
rq;
1551 err = open_dchannel(isac, rq);
1553 err = open_bchannel(ipac, rq);
1556 if (!try_module_get(ipac->
owner))
1561 dch->
dev.id, __builtin_return_address(0));
1562 module_put(ipac->
owner);
1565 err = channel_ctrl(ipac, arg);
1568 pr_debug(
"%s: unknown DCTRL command %x\n", ipac->
name, cmd);
1585 ipac->
hscx[0].off = 0;
1586 ipac->
hscx[1].off = 0x40;
1587 ipac->
hscx[0].fifo_size = 32;
1588 ipac->
hscx[1].fifo_size = 32;
1591 ipac->
hscx[0].off = 0;
1592 ipac->
hscx[1].off = 0x40;
1593 ipac->
hscx[0].fifo_size = 64;
1594 ipac->
hscx[1].fifo_size = 64;
1599 ipac->
hscx[0].fifo_size = 64;
1600 ipac->
hscx[1].fifo_size = 64;
1606 ipac->
isac.dch.dev.D.ctrl = ipac_dctrl;
1608 for (i = 0; i < 2; i++) {
1609 ipac->
hscx[
i].bch.nr = i + 1;
1610 set_channelmap(i + 1, ipac->
isac.dch.dev.channelmap);
1611 list_add(&ipac->
hscx[i].bch.ch.list,
1612 &ipac->
isac.dch.dev.bchannels);
1614 ipac->
hscx[i].fifo_size);
1615 ipac->
hscx[
i].bch.ch.nr = i + 1;
1616 ipac->
hscx[
i].bch.ch.send = &hscx_l2l1;
1617 ipac->
hscx[
i].bch.ch.ctrl = hscx_bctrl;
1619 ipac->
hscx[
i].ip = ipac;
1622 ipac->
hscx[
i].slot = (i == 0) ? 0x2f : 0x03;
1625 ipac->
init = ipac_init;
1642 isac_mod_cleanup(
void)
1644 pr_notice(
"mISDNipac module unloaded\n");