32 #include <linux/module.h>
35 #define ISAR_REV "2.1"
41 #define DEBUG_HW_FIRMWARE_FIFO 0x10000
43 static const u8 faxmodulation_s[] =
"3,24,48,72,73,74,96,97,98,121,122,145,146";
44 static const u8 faxmodulation[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121,
48 static void isar_setup(
struct isar_hw *);
51 waitforHIA(
struct isar_hw *isar,
int timeout)
56 while ((val & 1) && t) {
61 pr_debug(
"%s: HIA after %dus\n", isar->
name, timeout - t);
72 if (!waitforHIA(isar, 1000))
74 pr_debug(
"send_mbox(%02x,%02x,%d)\n", his, creg, len);
85 while (l < (
int)len) {
89 __func__, l, isar->
log);
95 waitforHIA(isar, 1000);
109 if (msg && isar->
clsb) {
114 while (l < (
int)isar->
clsb) {
116 1, isar->
log, 256, 1);
118 __func__, l, isar->
log);
127 get_irq_infos(
struct isar_hw *isar)
142 poll_mbox(
struct isar_hw *isar,
int maxdelay)
154 rcv_mbox(isar,
NULL);
156 pr_debug(
"%s: pulled %d bytes after %d us\n",
157 isar->
name, isar->
clsb, maxdelay - t);
162 ISARVersion(
struct isar_hw *isar)
173 if (!poll_mbox(isar, 1000))
176 if (isar->
clsb == 1) {
177 ver = isar->
buf[0] & 0xf;
188 u32 saved_debug = isar->
ch[0].bch.debug;
202 pr_err(
"%s: ISAR wrong version %d firmware download aborted\n",
208 pr_debug(
"%s: load firmware %d words (%d bytes)\n",
209 isar->
name, size / 2, size);
215 spin_unlock_irqrestore(isar->
hwlock, flags);
221 pr_debug(
"ISAR firmware block (%#x,%d,%#x)\n",
222 blk_head.sadr, blk_head.len, blk_head.d_key & 0xff);
224 if (cnt + left > size) {
225 pr_info(
"%s: firmware error have %d need %d words\n",
226 isar->
name, size, cnt + left);
233 pr_info(
"ISAR send_mbox dkey failed\n");
237 if (!poll_mbox(isar, 1000)) {
242 spin_unlock_irqrestore(isar->
hwlock, flags);
244 pr_info(
"ISAR wrong dkey response (%x,%x,%x)\n",
257 *mp++ = blk_head.sadr >> 8;
258 *mp++ = blk_head.sadr & 0xFF;
264 blk_head.sadr += noc;
273 pr_info(
"ISAR send_mbox prog failed\n");
277 if (!poll_mbox(isar, 1000)) {
278 pr_info(
"ISAR poll_mbox prog failed\n");
282 spin_unlock_irqrestore(isar->
hwlock, flags);
285 pr_info(
"ISAR wrong prog response (%x,%x,%x)\n",
291 pr_debug(
"%s: ISAR firmware block %d words loaded\n",
292 isar->
name, blk_head.len);
294 isar->
ch[0].bch.debug = saved_debug;
304 pr_info(
"ISAR send_mbox start dsp failed\n");
308 if (!poll_mbox(isar, 1000)) {
309 pr_info(
"ISAR poll_mbox start dsp failed\n");
314 pr_info(
"ISAR wrong start dsp response (%x,%x,%x)\n",
324 spin_unlock_irqrestore(isar->
hwlock, flags);
326 while ((!isar->
bstat) && cnt) {
331 pr_info(
"ISAR no general status event received\n");
335 pr_debug(
"%s: ISAR general status event %x\n",
344 pr_info(
"ISAR send_mbox self tst failed\n");
348 spin_unlock_irqrestore(isar->
hwlock, flags);
356 pr_info(
"ISAR no self tst response\n");
361 && (isar->
buf[0] == 0))
364 pr_info(
"ISAR selftest not OK %x/%x/%x\n",
372 pr_info(
"ISAR RQST SVN failed\n");
376 spin_unlock_irqrestore(isar->
hwlock, flags);
384 pr_info(
"ISAR no SVN response\n");
389 pr_notice(
"%s: ISAR software version %#x\n",
392 pr_info(
"%s: ISAR wrong swver response (%x,%x)"
393 " cnt(%d)\n", isar->
name, isar->
cmsb,
401 spin_unlock_irqrestore(isar->
hwlock, flags);
406 isar->
ch[0].bch.debug = saved_debug;
410 spin_unlock_irqrestore(isar->
hwlock, flags);
417 pr_debug(
"%s: HL->LL FAXIND %x\n", ch->
is->name, status);
422 isar_rcv_frame(
struct isar_ch *ch)
428 pr_debug(
"%s; ISAR zero len frame\n", ch->
is->name);
433 ch->
bch.dropcnt += ch->
is->clsb;
437 switch (ch->
bch.state) {
439 pr_debug(
"%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",
440 ch->
is->name, ch->
is->iis, ch->
is->cmsb, ch->
is->clsb);
448 pr_warning(
"%s.B%d: No bufferspace for %d bytes\n",
449 ch->
is->name, ch->
bch.nr, ch->
is->clsb);
459 pr_warning(
"%s.B%d: No bufferspace for %d bytes\n",
460 ch->
is->name, ch->
bch.nr, ch->
is->clsb);
465 pr_debug(
"%s: ISAR frame error %x len %d\n",
466 ch->
is->name, ch->
is->cmsb, ch->
is->clsb);
467 #ifdef ERROR_STATISTIC
480 rcv_mbox(ch->
is, ptr);
482 if (ch->
bch.rx_skb->len < 3) {
483 pr_debug(
"%s: ISAR frame to short %d\n",
484 ch->
is->name, ch->
bch.rx_skb->len);
494 pr_debug(
"%s: isar_rcv_frame: not ACTIV\n",
501 if (!ch->
bch.rx_skb) {
502 ch->
bch.rx_skb = mI_alloc_skb(ch->
bch.maxlen,
505 pr_info(
"%s: B receive out of memory\n",
513 pr_debug(
"%s: isar_rcv_frame: %d\n",
514 ch->
is->name, ch->
bch.rx_skb->len);
516 pr_debug(
"%s: isar_rcv_frame: no more data\n",
531 pr_debug(
"%s: isar_rcv_frame: unknown fax mode %x\n",
532 ch->
is->name, ch->
cmd);
539 if ((ch->
bch.rx_skb->len + ch->
is->clsb) >
540 (ch->
bch.maxlen + 2)) {
541 pr_info(
"%s: %s incoming packet too large\n",
542 ch->
is->name, __func__);
547 pr_info(
"%s: ISAR frame error %x len %d\n",
548 ch->
is->name, ch->
is->cmsb, ch->
is->clsb);
556 rcv_mbox(ch->
is, ptr);
558 if (ch->
bch.rx_skb->len < 3) {
559 pr_info(
"%s: ISAR frame to short %d\n",
560 ch->
is->name, ch->
bch.rx_skb->len);
568 pr_debug(
"%s: isar_rcv_frame: no more data\n",
580 pr_info(
"isar_rcv_frame protocol (%x)error\n", ch->
bch.state);
587 isar_fill_fifo(
struct isar_ch *ch)
593 pr_debug(
"%s: ch%d tx_skb %d tx_idx %d\n", ch->
is->name, ch->
bch.nr,
594 ch->
bch.tx_skb ? ch->
bch.tx_skb->len : -1, ch->
bch.tx_idx);
595 if (!(ch->
is->bstat &
598 if (!ch->
bch.tx_skb) {
606 0, count, ch->
is->buf);
609 count = ch->
bch.tx_skb->len - ch->
bch.tx_idx;
612 if (count > ch->
mml) {
618 ptr = ch->
bch.tx_skb->data + ch->
bch.tx_idx;
619 if (!ch->
bch.tx_idx) {
624 if ((ptr[0] == 0xff) && (ptr[1] == 0x13)) {
639 switch (ch->
bch.state) {
641 pr_info(
"%s: wrong protocol 0\n", __func__);
666 pr_info(
"%s: protocol(%x) error\n",
667 __func__, ch->
bch.state);
677 if ((!dpath) || (dpath > 2))
679 if (base->
dpath == dpath)
682 if (base->
dpath == dpath)
690 pr_debug(
"%s: %s ch%d tx_skb %d tx_idx %d\n", ch->
is->name, __func__,
691 ch->
bch.nr, ch->
bch.tx_skb ? ch->
bch.tx_skb->len : -1,
707 dev_kfree_skb(ch->
bch.tx_skb);
740 ch = sel_bch_isar(isar, 1);
742 if (ch->
bch.tx_skb && (ch->
bch.tx_skb->len >
749 if (rdm & BSTAT_RDM2) {
750 ch = sel_bch_isar(isar, 2);
752 if (ch->
bch.tx_skb && (ch->
bch.tx_skb->len >
761 const char *
dmril[] = {
"NO SPEED",
"1200/75",
"NODEF2",
"75/1200",
"NODEF4",
762 "300",
"600",
"1200",
"2400",
"4800",
"7200",
763 "9600nt",
"9600t",
"12000",
"14400",
"WRONG"};
764 const char *
dmrim[] = {
"NO MOD",
"NO DEF",
"V32/V32b",
"V22",
"V21",
765 "Bell103",
"V23",
"Bell202",
"V17",
"V29",
"V27ter"};
768 isar_pump_status_rsp(
struct isar_ch *ch) {
769 u8 ril = ch->
is->buf[0];
775 pr_info(
"%s: wrong pstrsp ril=%d\n", ch->
is->name, ril);
778 switch (ch->
is->buf[1]) {
823 pr_debug(
"%s: pump stev TIMER\n", ch->
is->name);
826 pr_debug(
"%s: pump stev CONNECT\n", ch->
is->name);
830 pr_debug(
"%s: pump stev NO CONNECT\n", ch->
is->name);
835 pr_debug(
"%s: pump stev V24 OFF\n", ch->
is->name);
838 pr_debug(
"%s: pump stev CTS ON\n", ch->
is->name);
841 pr_debug(
"%s pump stev CTS OFF\n", ch->
is->name);
844 pr_debug(
"%s: pump stev CARRIER ON\n", ch->
is->name);
849 pr_debug(
"%s: pump stev CARRIER OFF\n", ch->
is->name);
852 pr_debug(
"%s: pump stev DSR ON\n", ch->
is->name);
855 pr_debug(
"%s: pump stev DSR_OFF\n", ch->
is->name);
858 pr_debug(
"%s: pump stev REMOTE RETRAIN\n", ch->
is->name);
861 pr_debug(
"%s: pump stev REMOTE RENEGOTIATE\n", ch->
is->name);
864 pr_debug(
"%s: pump stev GSTN CLEAR\n", ch->
is->name);
867 pr_info(
"u%s: unknown pump stev %x\n", ch->
is->name, devt);
873 isar_pump_statev_fax(
struct isar_ch *ch,
u8 devt) {
879 pr_debug(
"%s: pump stev TIMER\n", ch->
is->name);
882 pr_debug(
"%s: pump stev RSP_READY\n", ch->
is->name);
894 pr_debug(
"%s: pump stev LINE_TX_H\n", ch->
is->name);
899 pr_debug(
"%s: pump stev LINE_TX_H wrong st %x\n",
905 pr_debug(
"%s: pump stev LINE_RX_H\n", ch->
is->name);
910 pr_debug(
"%s: pump stev LINE_RX_H wrong st %x\n",
916 pr_debug(
"%s: pump stev LINE_TX_B\n", ch->
is->name);
921 pr_debug(
"%s: pump stev LINE_TX_B wrong st %x\n",
927 pr_debug(
"%s: pump stev LINE_RX_B\n", ch->
is->name);
932 pr_debug(
"%s: pump stev LINE_RX_B wrong st %x\n",
938 pr_debug(
"%s: pump stev RSP_CONN\n", ch->
is->name);
943 int delay = (ch->
mod == 3) ? 1000 : 200;
957 pr_debug(
"%s: pump stev RSP_CONN wrong st %x\n",
962 pr_debug(
"%s: pump stev FLAGS_DET\n", ch->
is->name);
965 pr_debug(
"%s: pump stev RSP_DISC state(%d)\n",
993 pr_debug(
"%s: RSP_DISC unknown newcmd %x\n",
1012 pr_debug(
"%s: pump stev RSP_SILDET\n", ch->
is->name);
1026 pr_debug(
"%s: pump stev RSP_SILOFF\n", ch->
is->name);
1030 pr_debug(
"%s: pump stev RSP_FCERR try %d\n",
1038 pr_debug(
"%s: pump stev RSP_FCERR\n", ch->
is->name);
1054 get_irq_infos(isar);
1057 ch = sel_bch_isar(isar, isar->
iis >> 6);
1061 pr_debug(
"%s: ISAR spurious IIS_RDATA %x/%x/%x\n",
1070 check_send(isar, isar->
cmsb);
1073 #ifdef ERROR_STATISTIC
1074 ch = sel_bch_isar(isar, isar->
iis >> 6);
1082 pr_debug(
"%s: Buffer STEV dpath%d msb(%x)\n",
1087 ch = sel_bch_isar(isar, isar->
iis >> 6);
1089 rcv_mbox(isar,
NULL);
1091 isar_pump_statev_modem(ch, isar->
cmsb);
1093 isar_pump_statev_fax(ch, isar->
cmsb);
1096 tt = isar->
cmsb | 0x30;
1099 else if (tt == 0x3f)
1108 pr_debug(
"%s: ISAR IIS_PSTEV pm %d sta %x\n",
1112 pr_debug(
"%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",
1119 ch = sel_bch_isar(isar, isar->
iis >> 6);
1121 rcv_mbox(isar,
NULL);
1122 isar_pump_status_rsp(ch);
1124 pr_debug(
"%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",
1133 rcv_mbox(isar,
NULL);
1136 rcv_mbox(isar,
NULL);
1140 rcv_mbox(isar,
NULL);
1141 pr_debug(
"%s: unhandled msg iis(%x) ctrl(%x/%x)\n",
1149 ftimer_handler(
unsigned long data)
1153 pr_debug(
"%s: ftimer flags %lx\n", ch->
is->name, ch->
bch.Flags);
1160 setup_pump(
struct isar_ch *ch) {
1164 switch (ch->
bch.state) {
1218 setup_sart(
struct isar_ch *ch) {
1220 u8 ctrl, param[2] = {0, 0};
1222 switch (ch->
bch.state) {
1250 setup_iom2(
struct isar_ch *ch) {
1254 if (ch->
bch.nr == 2) {
1258 switch (ch->
bch.state) {
1262 msg[1] = ch->
dpath + 2;
1263 msg[3] = ch->
dpath + 2;
1288 switch (bprotocol) {
1305 pr_info(
"modeisar both pathes in use\n");
1321 pr_info(
"%s: ISAR modeisar analog functions"
1322 "only with DP1\n", ch->
is->name);
1327 pr_info(
"%s: protocol not known %x\n", ch->
is->name,
1332 pr_debug(
"%s: ISAR ch%d dp%d protocol %x->%x\n", ch->
is->name,
1334 ch->
bch.state = bprotocol;
1342 else if (ch->
dpath == 2)
1355 u8 ctrl = 0, nom = 0, p1 = 0;
1357 pr_debug(
"%s: isar_pump_cmd %x/%x state(%x)\n",
1358 ch->
is->name, cmd, para, ch->
bch.state);
1459 isar_setup(
struct isar_hw *isar)
1466 for (i = 0; i < 2; i++) {
1471 isar->
ch[
i].bch.state = 0;
1472 isar->
ch[
i].dpath = i + 1;
1478 isar_l2l1(
struct mISDNchannel *ch,
struct sk_buff *
skb)
1493 isar_fill_fifo(ich);
1495 spin_unlock_irqrestore(ich->
is->hwlock, flags);
1500 ret = modeisar(ich, ch->protocol);
1503 spin_unlock_irqrestore(ich->
is->hwlock, flags);
1512 spin_unlock_irqrestore(ich->
is->hwlock, flags);
1519 pr_debug(
"%s: PH_CONTROL | REQUEST %x/%x\n", ich->
is->name,
1535 spin_unlock_irqrestore(ich->
is->hwlock, flags);
1537 pr_info(
"%s: DTMF send wrong protocol %x\n",
1538 __func__, bch->
state);
1544 if (faxmodulation[
id] == *val)
1546 if ((FAXMODCNT >
id) &&
1548 pr_debug(
"%s: isar: new mod\n", ich->
is->name);
1549 isar_pump_cmd(ich, hh->
id, *val);
1552 pr_info(
"%s: wrong modulation\n",
1559 pr_info(
"%s: unknown PH_CONTROL_REQ %x\n",
1560 ich->
is->name, hh->
id);
1564 pr_info(
"%s: %s unknown prim(%x,%x)\n",
1565 ich->
is->name, __func__, hh->
prim, hh->
id);
1580 isar_bctrl(
struct mISDNchannel *ch,
u32 cmd,
void *
arg)
1587 pr_debug(
"%s: %s cmd:%x %p\n", ich->
is->name, __func__, cmd, arg);
1595 spin_unlock_irqrestore(ich->
is->hwlock, flags);
1598 module_put(ich->
is->owner);
1602 ret = channel_bctrl(bch, arg);
1605 pr_info(
"%s: %s unknown prim(%x)\n",
1606 ich->
is->name, __func__, cmd);
1612 free_isar(
struct isar_hw *isar)
1623 init_isar(
struct isar_hw *isar)
1628 isar->
version = ISARVersion(isar);
1630 pr_notice(
"%s: Testing version %d (%d time)\n",
1638 isar->
ch[0].ftimer.function = &ftimer_handler;
1639 isar->
ch[0].ftimer.data = (
long)&isar->
ch[0];
1642 isar->
ch[1].ftimer.function = &ftimer_handler;
1643 isar->
ch[1].ftimer.data = (
long)&isar->
ch[1];
1650 isar_open(
struct isar_hw *isar,
struct channel_req *
rq)
1654 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1658 bch = &isar->
ch[rq->adr.channel - 1].bch;
1661 bch->
ch.protocol = rq->protocol;
1672 for (i = 0; i < 2; i++) {
1673 isar->
ch[
i].bch.nr = i + 1;
1675 isar->
ch[
i].bch.ch.nr = i + 1;
1676 isar->
ch[
i].bch.ch.send = &isar_l2l1;
1677 isar->
ch[
i].bch.ch.ctrl = isar_bctrl;
1678 isar->
ch[
i].bch.hw =
hw;
1679 isar->
ch[
i].is = isar;
1682 isar->
init = &init_isar;
1685 isar->
open = &isar_open;
1697 static int __init isar_mod_init(
void)
1703 static void __exit isar_mod_cleanup(
void)
1705 pr_notice(
"mISDN: ISAR module unloaded\n");