Path: blob/master/drivers/isdn/hardware/mISDN/mISDNisar.c
15111 views
/*1* mISDNisar.c ISAR (Siemens PSB 7110) specific functions2*3* Author Karsten Keil ([email protected])4*5* Copyright 2009 by Karsten Keil <[email protected]>6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.19*20*/2122/* define this to enable static debug messages, if you kernel supports23* dynamic debugging, you should use debugfs for this24*/25/* #define DEBUG */2627#include <linux/gfp.h>28#include <linux/delay.h>29#include <linux/vmalloc.h>30#include <linux/mISDNhw.h>31#include "isar.h"3233#define ISAR_REV "2.1"3435MODULE_AUTHOR("Karsten Keil");36MODULE_LICENSE("GPL v2");37MODULE_VERSION(ISAR_REV);3839#define DEBUG_HW_FIRMWARE_FIFO 0x100004041static const u8 faxmodulation_s[] = "3,24,48,72,73,74,96,97,98,121,122,145,146";42static const u8 faxmodulation[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121,43122, 145, 146};44#define FAXMODCNT 134546static void isar_setup(struct isar_hw *);4748static inline int49waitforHIA(struct isar_hw *isar, int timeout)50{51int t = timeout;52u8 val = isar->read_reg(isar->hw, ISAR_HIA);5354while ((val & 1) && t) {55udelay(1);56t--;57val = isar->read_reg(isar->hw, ISAR_HIA);58}59pr_debug("%s: HIA after %dus\n", isar->name, timeout - t);60return timeout;61}6263/*64* send msg to ISAR mailbox65* if msg is NULL use isar->buf66*/67static int68send_mbox(struct isar_hw *isar, u8 his, u8 creg, u8 len, u8 *msg)69{70if (!waitforHIA(isar, 1000))71return 0;72pr_debug("send_mbox(%02x,%02x,%d)\n", his, creg, len);73isar->write_reg(isar->hw, ISAR_CTRL_H, creg);74isar->write_reg(isar->hw, ISAR_CTRL_L, len);75isar->write_reg(isar->hw, ISAR_WADR, 0);76if (!msg)77msg = isar->buf;78if (msg && len) {79isar->write_fifo(isar->hw, ISAR_MBOX, msg, len);80if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) {81int l = 0;8283while (l < (int)len) {84hex_dump_to_buffer(msg + l, len - l, 32, 1,85isar->log, 256, 1);86pr_debug("%s: %s %02x: %s\n", isar->name,87__func__, l, isar->log);88l += 32;89}90}91}92isar->write_reg(isar->hw, ISAR_HIS, his);93waitforHIA(isar, 1000);94return 1;95}9697/*98* receive message from ISAR mailbox99* if msg is NULL use isar->buf100*/101static void102rcv_mbox(struct isar_hw *isar, u8 *msg)103{104if (!msg)105msg = isar->buf;106isar->write_reg(isar->hw, ISAR_RADR, 0);107if (msg && isar->clsb) {108isar->read_fifo(isar->hw, ISAR_MBOX, msg, isar->clsb);109if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) {110int l = 0;111112while (l < (int)isar->clsb) {113hex_dump_to_buffer(msg + l, isar->clsb - l, 32,1141, isar->log, 256, 1);115pr_debug("%s: %s %02x: %s\n", isar->name,116__func__, l, isar->log);117l += 32;118}119}120}121isar->write_reg(isar->hw, ISAR_IIA, 0);122}123124static inline void125get_irq_infos(struct isar_hw *isar)126{127isar->iis = isar->read_reg(isar->hw, ISAR_IIS);128isar->cmsb = isar->read_reg(isar->hw, ISAR_CTRL_H);129isar->clsb = isar->read_reg(isar->hw, ISAR_CTRL_L);130pr_debug("%s: rcv_mbox(%02x,%02x,%d)\n", isar->name,131isar->iis, isar->cmsb, isar->clsb);132}133134/*135* poll answer message from ISAR mailbox136* should be used only with ISAR IRQs disabled before DSP was started137*138*/139static int140poll_mbox(struct isar_hw *isar, int maxdelay)141{142int t = maxdelay;143u8 irq;144145irq = isar->read_reg(isar->hw, ISAR_IRQBIT);146while (t && !(irq & ISAR_IRQSTA)) {147udelay(1);148t--;149}150if (t) {151get_irq_infos(isar);152rcv_mbox(isar, NULL);153}154pr_debug("%s: pulled %d bytes after %d us\n",155isar->name, isar->clsb, maxdelay - t);156return t;157}158159static int160ISARVersion(struct isar_hw *isar)161{162int ver;163164/* disable ISAR IRQ */165isar->write_reg(isar->hw, ISAR_IRQBIT, 0);166isar->buf[0] = ISAR_MSG_HWVER;167isar->buf[1] = 0;168isar->buf[2] = 1;169if (!send_mbox(isar, ISAR_HIS_VNR, 0, 3, NULL))170return -1;171if (!poll_mbox(isar, 1000))172return -2;173if (isar->iis == ISAR_IIS_VNR) {174if (isar->clsb == 1) {175ver = isar->buf[0] & 0xf;176return ver;177}178return -3;179}180return -4;181}182183static int184load_firmware(struct isar_hw *isar, const u8 *buf, int size)185{186u32 saved_debug = isar->ch[0].bch.debug;187int ret, cnt;188u8 nom, noc;189u16 left, val, *sp = (u16 *)buf;190u8 *mp;191u_long flags;192193struct {194u16 sadr;195u16 len;196u16 d_key;197} blk_head;198199if (1 != isar->version) {200pr_err("%s: ISAR wrong version %d firmware download aborted\n",201isar->name, isar->version);202return -EINVAL;203}204if (!(saved_debug & DEBUG_HW_FIRMWARE_FIFO))205isar->ch[0].bch.debug &= ~DEBUG_HW_BFIFO;206pr_debug("%s: load firmware %d words (%d bytes)\n",207isar->name, size/2, size);208cnt = 0;209size /= 2;210/* disable ISAR IRQ */211spin_lock_irqsave(isar->hwlock, flags);212isar->write_reg(isar->hw, ISAR_IRQBIT, 0);213spin_unlock_irqrestore(isar->hwlock, flags);214while (cnt < size) {215blk_head.sadr = le16_to_cpu(*sp++);216blk_head.len = le16_to_cpu(*sp++);217blk_head.d_key = le16_to_cpu(*sp++);218cnt += 3;219pr_debug("ISAR firmware block (%#x,%d,%#x)\n",220blk_head.sadr, blk_head.len, blk_head.d_key & 0xff);221left = blk_head.len;222if (cnt + left > size) {223pr_info("%s: firmware error have %d need %d words\n",224isar->name, size, cnt + left);225ret = -EINVAL;226goto reterrflg;227}228spin_lock_irqsave(isar->hwlock, flags);229if (!send_mbox(isar, ISAR_HIS_DKEY, blk_head.d_key & 0xff,2300, NULL)) {231pr_info("ISAR send_mbox dkey failed\n");232ret = -ETIME;233goto reterror;234}235if (!poll_mbox(isar, 1000)) {236pr_warning("ISAR poll_mbox dkey failed\n");237ret = -ETIME;238goto reterror;239}240spin_unlock_irqrestore(isar->hwlock, flags);241if ((isar->iis != ISAR_IIS_DKEY) || isar->cmsb || isar->clsb) {242pr_info("ISAR wrong dkey response (%x,%x,%x)\n",243isar->iis, isar->cmsb, isar->clsb);244ret = 1;245goto reterrflg;246}247while (left > 0) {248if (left > 126)249noc = 126;250else251noc = left;252nom = (2 * noc) + 3;253mp = isar->buf;254/* the ISAR is big endian */255*mp++ = blk_head.sadr >> 8;256*mp++ = blk_head.sadr & 0xFF;257left -= noc;258cnt += noc;259*mp++ = noc;260pr_debug("%s: load %3d words at %04x\n", isar->name,261noc, blk_head.sadr);262blk_head.sadr += noc;263while (noc) {264val = le16_to_cpu(*sp++);265*mp++ = val >> 8;266*mp++ = val & 0xFF;267noc--;268}269spin_lock_irqsave(isar->hwlock, flags);270if (!send_mbox(isar, ISAR_HIS_FIRM, 0, nom, NULL)) {271pr_info("ISAR send_mbox prog failed\n");272ret = -ETIME;273goto reterror;274}275if (!poll_mbox(isar, 1000)) {276pr_info("ISAR poll_mbox prog failed\n");277ret = -ETIME;278goto reterror;279}280spin_unlock_irqrestore(isar->hwlock, flags);281if ((isar->iis != ISAR_IIS_FIRM) ||282isar->cmsb || isar->clsb) {283pr_info("ISAR wrong prog response (%x,%x,%x)\n",284isar->iis, isar->cmsb, isar->clsb);285ret = -EIO;286goto reterrflg;287}288}289pr_debug("%s: ISAR firmware block %d words loaded\n",290isar->name, blk_head.len);291}292isar->ch[0].bch.debug = saved_debug;293/* 10ms delay */294cnt = 10;295while (cnt--)296mdelay(1);297isar->buf[0] = 0xff;298isar->buf[1] = 0xfe;299isar->bstat = 0;300spin_lock_irqsave(isar->hwlock, flags);301if (!send_mbox(isar, ISAR_HIS_STDSP, 0, 2, NULL)) {302pr_info("ISAR send_mbox start dsp failed\n");303ret = -ETIME;304goto reterror;305}306if (!poll_mbox(isar, 1000)) {307pr_info("ISAR poll_mbox start dsp failed\n");308ret = -ETIME;309goto reterror;310}311if ((isar->iis != ISAR_IIS_STDSP) || isar->cmsb || isar->clsb) {312pr_info("ISAR wrong start dsp response (%x,%x,%x)\n",313isar->iis, isar->cmsb, isar->clsb);314ret = -EIO;315goto reterror;316} else317pr_debug("%s: ISAR start dsp success\n", isar->name);318319/* NORMAL mode entered */320/* Enable IRQs of ISAR */321isar->write_reg(isar->hw, ISAR_IRQBIT, ISAR_IRQSTA);322spin_unlock_irqrestore(isar->hwlock, flags);323cnt = 1000; /* max 1s */324while ((!isar->bstat) && cnt) {325mdelay(1);326cnt--;327}328if (!cnt) {329pr_info("ISAR no general status event received\n");330ret = -ETIME;331goto reterrflg;332} else333pr_debug("%s: ISAR general status event %x\n",334isar->name, isar->bstat);335/* 10ms delay */336cnt = 10;337while (cnt--)338mdelay(1);339isar->iis = 0;340spin_lock_irqsave(isar->hwlock, flags);341if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_STST, 0, NULL)) {342pr_info("ISAR send_mbox self tst failed\n");343ret = -ETIME;344goto reterror;345}346spin_unlock_irqrestore(isar->hwlock, flags);347cnt = 10000; /* max 100 ms */348while ((isar->iis != ISAR_IIS_DIAG) && cnt) {349udelay(10);350cnt--;351}352mdelay(1);353if (!cnt) {354pr_info("ISAR no self tst response\n");355ret = -ETIME;356goto reterrflg;357}358if ((isar->cmsb == ISAR_CTRL_STST) && (isar->clsb == 1)359&& (isar->buf[0] == 0))360pr_debug("%s: ISAR selftest OK\n", isar->name);361else {362pr_info("ISAR selftest not OK %x/%x/%x\n",363isar->cmsb, isar->clsb, isar->buf[0]);364ret = -EIO;365goto reterrflg;366}367spin_lock_irqsave(isar->hwlock, flags);368isar->iis = 0;369if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_SWVER, 0, NULL)) {370pr_info("ISAR RQST SVN failed\n");371ret = -ETIME;372goto reterror;373}374spin_unlock_irqrestore(isar->hwlock, flags);375cnt = 30000; /* max 300 ms */376while ((isar->iis != ISAR_IIS_DIAG) && cnt) {377udelay(10);378cnt--;379}380mdelay(1);381if (!cnt) {382pr_info("ISAR no SVN response\n");383ret = -ETIME;384goto reterrflg;385} else {386if ((isar->cmsb == ISAR_CTRL_SWVER) && (isar->clsb == 1)) {387pr_notice("%s: ISAR software version %#x\n",388isar->name, isar->buf[0]);389} else {390pr_info("%s: ISAR wrong swver response (%x,%x)"391" cnt(%d)\n", isar->name, isar->cmsb,392isar->clsb, cnt);393ret = -EIO;394goto reterrflg;395}396}397spin_lock_irqsave(isar->hwlock, flags);398isar_setup(isar);399spin_unlock_irqrestore(isar->hwlock, flags);400ret = 0;401reterrflg:402spin_lock_irqsave(isar->hwlock, flags);403reterror:404isar->ch[0].bch.debug = saved_debug;405if (ret)406/* disable ISAR IRQ */407isar->write_reg(isar->hw, ISAR_IRQBIT, 0);408spin_unlock_irqrestore(isar->hwlock, flags);409return ret;410}411412static inline void413deliver_status(struct isar_ch *ch, int status)414{415pr_debug("%s: HL->LL FAXIND %x\n", ch->is->name, status);416_queue_data(&ch->bch.ch, PH_CONTROL_IND, status, 0, NULL, GFP_ATOMIC);417}418419static inline void420isar_rcv_frame(struct isar_ch *ch)421{422u8 *ptr;423424if (!ch->is->clsb) {425pr_debug("%s; ISAR zero len frame\n", ch->is->name);426ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);427return;428}429switch (ch->bch.state) {430case ISDN_P_NONE:431pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",432ch->is->name, ch->is->iis, ch->is->cmsb, ch->is->clsb);433ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);434break;435case ISDN_P_B_RAW:436case ISDN_P_B_L2DTMF:437case ISDN_P_B_MODEM_ASYNC:438if (!ch->bch.rx_skb) {439ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,440GFP_ATOMIC);441if (unlikely(!ch->bch.rx_skb)) {442pr_info("%s: B receive out of memory\n",443ch->is->name);444ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);445break;446}447}448rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));449recv_Bchannel(&ch->bch, 0);450break;451case ISDN_P_B_HDLC:452if (!ch->bch.rx_skb) {453ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,454GFP_ATOMIC);455if (unlikely(!ch->bch.rx_skb)) {456pr_info("%s: B receive out of memory\n",457ch->is->name);458ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);459break;460}461}462if ((ch->bch.rx_skb->len + ch->is->clsb) >463(ch->bch.maxlen + 2)) {464pr_debug("%s: incoming packet too large\n",465ch->is->name);466ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);467skb_trim(ch->bch.rx_skb, 0);468break;469}470if (ch->is->cmsb & HDLC_ERROR) {471pr_debug("%s: ISAR frame error %x len %d\n",472ch->is->name, ch->is->cmsb, ch->is->clsb);473#ifdef ERROR_STATISTIC474if (ch->is->cmsb & HDLC_ERR_RER)475ch->bch.err_inv++;476if (ch->is->cmsb & HDLC_ERR_CER)477ch->bch.err_crc++;478#endif479skb_trim(ch->bch.rx_skb, 0);480ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);481break;482}483if (ch->is->cmsb & HDLC_FSD)484skb_trim(ch->bch.rx_skb, 0);485ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);486rcv_mbox(ch->is, ptr);487if (ch->is->cmsb & HDLC_FED) {488if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */489pr_debug("%s: ISAR frame to short %d\n",490ch->is->name, ch->bch.rx_skb->len);491skb_trim(ch->bch.rx_skb, 0);492break;493}494skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);495recv_Bchannel(&ch->bch, 0);496}497break;498case ISDN_P_B_T30_FAX:499if (ch->state != STFAX_ACTIV) {500pr_debug("%s: isar_rcv_frame: not ACTIV\n",501ch->is->name);502ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);503if (ch->bch.rx_skb)504skb_trim(ch->bch.rx_skb, 0);505break;506}507if (!ch->bch.rx_skb) {508ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,509GFP_ATOMIC);510if (unlikely(!ch->bch.rx_skb)) {511pr_info("%s: B receive out of memory\n",512__func__);513ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);514break;515}516}517if (ch->cmd == PCTRL_CMD_FRM) {518rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));519pr_debug("%s: isar_rcv_frame: %d\n",520ch->is->name, ch->bch.rx_skb->len);521if (ch->is->cmsb & SART_NMD) { /* ABORT */522pr_debug("%s: isar_rcv_frame: no more data\n",523ch->is->name);524ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);525send_mbox(ch->is, SET_DPS(ch->dpath) |526ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,5270, NULL);528ch->state = STFAX_ESCAPE;529/* set_skb_flag(skb, DF_NOMOREDATA); */530}531recv_Bchannel(&ch->bch, 0);532if (ch->is->cmsb & SART_NMD)533deliver_status(ch, HW_MOD_NOCARR);534break;535}536if (ch->cmd != PCTRL_CMD_FRH) {537pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n",538ch->is->name, ch->cmd);539ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);540if (ch->bch.rx_skb)541skb_trim(ch->bch.rx_skb, 0);542break;543}544/* PCTRL_CMD_FRH */545if ((ch->bch.rx_skb->len + ch->is->clsb) >546(ch->bch.maxlen + 2)) {547pr_info("%s: %s incoming packet too large\n",548ch->is->name, __func__);549ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);550skb_trim(ch->bch.rx_skb, 0);551break;552} else if (ch->is->cmsb & HDLC_ERROR) {553pr_info("%s: ISAR frame error %x len %d\n",554ch->is->name, ch->is->cmsb, ch->is->clsb);555skb_trim(ch->bch.rx_skb, 0);556ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);557break;558}559if (ch->is->cmsb & HDLC_FSD)560skb_trim(ch->bch.rx_skb, 0);561ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);562rcv_mbox(ch->is, ptr);563if (ch->is->cmsb & HDLC_FED) {564if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */565pr_info("%s: ISAR frame to short %d\n",566ch->is->name, ch->bch.rx_skb->len);567skb_trim(ch->bch.rx_skb, 0);568break;569}570skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);571recv_Bchannel(&ch->bch, 0);572}573if (ch->is->cmsb & SART_NMD) { /* ABORT */574pr_debug("%s: isar_rcv_frame: no more data\n",575ch->is->name);576ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);577if (ch->bch.rx_skb)578skb_trim(ch->bch.rx_skb, 0);579send_mbox(ch->is, SET_DPS(ch->dpath) |580ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC, 0, NULL);581ch->state = STFAX_ESCAPE;582deliver_status(ch, HW_MOD_NOCARR);583}584break;585default:586pr_info("isar_rcv_frame protocol (%x)error\n", ch->bch.state);587ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);588break;589}590}591592static void593isar_fill_fifo(struct isar_ch *ch)594{595int count;596u8 msb;597u8 *ptr;598599pr_debug("%s: ch%d tx_skb %p tx_idx %d\n",600ch->is->name, ch->bch.nr, ch->bch.tx_skb, ch->bch.tx_idx);601if (!ch->bch.tx_skb)602return;603count = ch->bch.tx_skb->len - ch->bch.tx_idx;604if (count <= 0)605return;606if (!(ch->is->bstat &607(ch->dpath == 1 ? BSTAT_RDM1 : BSTAT_RDM2)))608return;609if (count > ch->mml) {610msb = 0;611count = ch->mml;612} else {613msb = HDLC_FED;614}615ptr = ch->bch.tx_skb->data + ch->bch.tx_idx;616if (!ch->bch.tx_idx) {617pr_debug("%s: frame start\n", ch->is->name);618if ((ch->bch.state == ISDN_P_B_T30_FAX) &&619(ch->cmd == PCTRL_CMD_FTH)) {620if (count > 1) {621if ((ptr[0] == 0xff) && (ptr[1] == 0x13)) {622/* last frame */623test_and_set_bit(FLG_LASTDATA,624&ch->bch.Flags);625pr_debug("%s: set LASTDATA\n",626ch->is->name);627if (msb == HDLC_FED)628test_and_set_bit(FLG_DLEETX,629&ch->bch.Flags);630}631}632}633msb |= HDLC_FST;634}635ch->bch.tx_idx += count;636switch (ch->bch.state) {637case ISDN_P_NONE:638pr_info("%s: wrong protocol 0\n", __func__);639break;640case ISDN_P_B_RAW:641case ISDN_P_B_L2DTMF:642case ISDN_P_B_MODEM_ASYNC:643send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,6440, count, ptr);645break;646case ISDN_P_B_HDLC:647send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,648msb, count, ptr);649break;650case ISDN_P_B_T30_FAX:651if (ch->state != STFAX_ACTIV)652pr_debug("%s: not ACTIV\n", ch->is->name);653else if (ch->cmd == PCTRL_CMD_FTH)654send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,655msb, count, ptr);656else if (ch->cmd == PCTRL_CMD_FTM)657send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,6580, count, ptr);659else660pr_debug("%s: not FTH/FTM\n", ch->is->name);661break;662default:663pr_info("%s: protocol(%x) error\n",664__func__, ch->bch.state);665break;666}667}668669static inline struct isar_ch *670sel_bch_isar(struct isar_hw *isar, u8 dpath)671{672struct isar_ch *base = &isar->ch[0];673674if ((!dpath) || (dpath > 2))675return NULL;676if (base->dpath == dpath)677return base;678base++;679if (base->dpath == dpath)680return base;681return NULL;682}683684static void685send_next(struct isar_ch *ch)686{687pr_debug("%s: %s ch%d tx_skb %p tx_idx %d\n",688ch->is->name, __func__, ch->bch.nr,689ch->bch.tx_skb, ch->bch.tx_idx);690if (ch->bch.state == ISDN_P_B_T30_FAX) {691if (ch->cmd == PCTRL_CMD_FTH) {692if (test_bit(FLG_LASTDATA, &ch->bch.Flags)) {693pr_debug("set NMD_DATA\n");694test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);695}696} else if (ch->cmd == PCTRL_CMD_FTM) {697if (test_bit(FLG_DLEETX, &ch->bch.Flags)) {698test_and_set_bit(FLG_LASTDATA, &ch->bch.Flags);699test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);700}701}702}703if (ch->bch.tx_skb) {704/* send confirm, on trans, free on hdlc. */705if (test_bit(FLG_TRANSPARENT, &ch->bch.Flags))706confirm_Bsend(&ch->bch);707dev_kfree_skb(ch->bch.tx_skb);708}709if (get_next_bframe(&ch->bch))710isar_fill_fifo(ch);711else {712if (test_and_clear_bit(FLG_DLEETX, &ch->bch.Flags)) {713if (test_and_clear_bit(FLG_LASTDATA,714&ch->bch.Flags)) {715if (test_and_clear_bit(FLG_NMD_DATA,716&ch->bch.Flags)) {717u8 zd = 0;718send_mbox(ch->is, SET_DPS(ch->dpath) |719ISAR_HIS_SDATA, 0x01, 1, &zd);720}721test_and_set_bit(FLG_LL_OK, &ch->bch.Flags);722} else {723deliver_status(ch, HW_MOD_CONNECT);724}725}726}727}728729static void730check_send(struct isar_hw *isar, u8 rdm)731{732struct isar_ch *ch;733734pr_debug("%s: rdm %x\n", isar->name, rdm);735if (rdm & BSTAT_RDM1) {736ch = sel_bch_isar(isar, 1);737if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {738if (ch->bch.tx_skb && (ch->bch.tx_skb->len >739ch->bch.tx_idx))740isar_fill_fifo(ch);741else742send_next(ch);743}744}745if (rdm & BSTAT_RDM2) {746ch = sel_bch_isar(isar, 2);747if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {748if (ch->bch.tx_skb && (ch->bch.tx_skb->len >749ch->bch.tx_idx))750isar_fill_fifo(ch);751else752send_next(ch);753}754}755}756757const char *dmril[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",758"300", "600", "1200", "2400", "4800", "7200",759"9600nt", "9600t", "12000", "14400", "WRONG"};760const char *dmrim[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",761"Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};762763static void764isar_pump_status_rsp(struct isar_ch *ch) {765u8 ril = ch->is->buf[0];766u8 rim;767768if (!test_and_clear_bit(ISAR_RATE_REQ, &ch->is->Flags))769return;770if (ril > 14) {771pr_info("%s: wrong pstrsp ril=%d\n", ch->is->name, ril);772ril = 15;773}774switch (ch->is->buf[1]) {775case 0:776rim = 0;777break;778case 0x20:779rim = 2;780break;781case 0x40:782rim = 3;783break;784case 0x41:785rim = 4;786break;787case 0x51:788rim = 5;789break;790case 0x61:791rim = 6;792break;793case 0x71:794rim = 7;795break;796case 0x82:797rim = 8;798break;799case 0x92:800rim = 9;801break;802case 0xa2:803rim = 10;804break;805default:806rim = 1;807break;808}809sprintf(ch->conmsg, "%s %s", dmril[ril], dmrim[rim]);810pr_debug("%s: pump strsp %s\n", ch->is->name, ch->conmsg);811}812813static void814isar_pump_statev_modem(struct isar_ch *ch, u8 devt) {815u8 dps = SET_DPS(ch->dpath);816817switch (devt) {818case PSEV_10MS_TIMER:819pr_debug("%s: pump stev TIMER\n", ch->is->name);820break;821case PSEV_CON_ON:822pr_debug("%s: pump stev CONNECT\n", ch->is->name);823deliver_status(ch, HW_MOD_CONNECT);824break;825case PSEV_CON_OFF:826pr_debug("%s: pump stev NO CONNECT\n", ch->is->name);827send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);828deliver_status(ch, HW_MOD_NOCARR);829break;830case PSEV_V24_OFF:831pr_debug("%s: pump stev V24 OFF\n", ch->is->name);832break;833case PSEV_CTS_ON:834pr_debug("%s: pump stev CTS ON\n", ch->is->name);835break;836case PSEV_CTS_OFF:837pr_debug("%s pump stev CTS OFF\n", ch->is->name);838break;839case PSEV_DCD_ON:840pr_debug("%s: pump stev CARRIER ON\n", ch->is->name);841test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);842send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);843break;844case PSEV_DCD_OFF:845pr_debug("%s: pump stev CARRIER OFF\n", ch->is->name);846break;847case PSEV_DSR_ON:848pr_debug("%s: pump stev DSR ON\n", ch->is->name);849break;850case PSEV_DSR_OFF:851pr_debug("%s: pump stev DSR_OFF\n", ch->is->name);852break;853case PSEV_REM_RET:854pr_debug("%s: pump stev REMOTE RETRAIN\n", ch->is->name);855break;856case PSEV_REM_REN:857pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch->is->name);858break;859case PSEV_GSTN_CLR:860pr_debug("%s: pump stev GSTN CLEAR\n", ch->is->name);861break;862default:863pr_info("u%s: unknown pump stev %x\n", ch->is->name, devt);864break;865}866}867868static void869isar_pump_statev_fax(struct isar_ch *ch, u8 devt) {870u8 dps = SET_DPS(ch->dpath);871u8 p1;872873switch (devt) {874case PSEV_10MS_TIMER:875pr_debug("%s: pump stev TIMER\n", ch->is->name);876break;877case PSEV_RSP_READY:878pr_debug("%s: pump stev RSP_READY\n", ch->is->name);879ch->state = STFAX_READY;880deliver_status(ch, HW_MOD_READY);881#ifdef AUTOCON882if (test_bit(BC_FLG_ORIG, &ch->bch.Flags))883isar_pump_cmd(bch, HW_MOD_FRH, 3);884else885isar_pump_cmd(bch, HW_MOD_FTH, 3);886#endif887break;888case PSEV_LINE_TX_H:889if (ch->state == STFAX_LINE) {890pr_debug("%s: pump stev LINE_TX_H\n", ch->is->name);891ch->state = STFAX_CONT;892send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,893PCTRL_CMD_CONT, 0, NULL);894} else {895pr_debug("%s: pump stev LINE_TX_H wrong st %x\n",896ch->is->name, ch->state);897}898break;899case PSEV_LINE_RX_H:900if (ch->state == STFAX_LINE) {901pr_debug("%s: pump stev LINE_RX_H\n", ch->is->name);902ch->state = STFAX_CONT;903send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,904PCTRL_CMD_CONT, 0, NULL);905} else {906pr_debug("%s: pump stev LINE_RX_H wrong st %x\n",907ch->is->name, ch->state);908}909break;910case PSEV_LINE_TX_B:911if (ch->state == STFAX_LINE) {912pr_debug("%s: pump stev LINE_TX_B\n", ch->is->name);913ch->state = STFAX_CONT;914send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,915PCTRL_CMD_CONT, 0, NULL);916} else {917pr_debug("%s: pump stev LINE_TX_B wrong st %x\n",918ch->is->name, ch->state);919}920break;921case PSEV_LINE_RX_B:922if (ch->state == STFAX_LINE) {923pr_debug("%s: pump stev LINE_RX_B\n", ch->is->name);924ch->state = STFAX_CONT;925send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,926PCTRL_CMD_CONT, 0, NULL);927} else {928pr_debug("%s: pump stev LINE_RX_B wrong st %x\n",929ch->is->name, ch->state);930}931break;932case PSEV_RSP_CONN:933if (ch->state == STFAX_CONT) {934pr_debug("%s: pump stev RSP_CONN\n", ch->is->name);935ch->state = STFAX_ACTIV;936test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);937send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);938if (ch->cmd == PCTRL_CMD_FTH) {939int delay = (ch->mod == 3) ? 1000 : 200;940/* 1s (200 ms) Flags before data */941if (test_and_set_bit(FLG_FTI_RUN,942&ch->bch.Flags))943del_timer(&ch->ftimer);944ch->ftimer.expires =945jiffies + ((delay * HZ)/1000);946test_and_set_bit(FLG_LL_CONN,947&ch->bch.Flags);948add_timer(&ch->ftimer);949} else {950deliver_status(ch, HW_MOD_CONNECT);951}952} else {953pr_debug("%s: pump stev RSP_CONN wrong st %x\n",954ch->is->name, ch->state);955}956break;957case PSEV_FLAGS_DET:958pr_debug("%s: pump stev FLAGS_DET\n", ch->is->name);959break;960case PSEV_RSP_DISC:961pr_debug("%s: pump stev RSP_DISC state(%d)\n",962ch->is->name, ch->state);963if (ch->state == STFAX_ESCAPE) {964p1 = 5;965switch (ch->newcmd) {966case 0:967ch->state = STFAX_READY;968break;969case PCTRL_CMD_FTM:970p1 = 2;971case PCTRL_CMD_FTH:972send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,973PCTRL_CMD_SILON, 1, &p1);974ch->state = STFAX_SILDET;975break;976case PCTRL_CMD_FRH:977case PCTRL_CMD_FRM:978ch->mod = ch->newmod;979p1 = ch->newmod;980ch->newmod = 0;981ch->cmd = ch->newcmd;982ch->newcmd = 0;983send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,984ch->cmd, 1, &p1);985ch->state = STFAX_LINE;986ch->try_mod = 3;987break;988default:989pr_debug("%s: RSP_DISC unknown newcmd %x\n",990ch->is->name, ch->newcmd);991break;992}993} else if (ch->state == STFAX_ACTIV) {994if (test_and_clear_bit(FLG_LL_OK, &ch->bch.Flags))995deliver_status(ch, HW_MOD_OK);996else if (ch->cmd == PCTRL_CMD_FRM)997deliver_status(ch, HW_MOD_NOCARR);998else999deliver_status(ch, HW_MOD_FCERROR);1000ch->state = STFAX_READY;1001} else if (ch->state != STFAX_SILDET) {1002/* ignore in STFAX_SILDET */1003ch->state = STFAX_READY;1004deliver_status(ch, HW_MOD_FCERROR);1005}1006break;1007case PSEV_RSP_SILDET:1008pr_debug("%s: pump stev RSP_SILDET\n", ch->is->name);1009if (ch->state == STFAX_SILDET) {1010ch->mod = ch->newmod;1011p1 = ch->newmod;1012ch->newmod = 0;1013ch->cmd = ch->newcmd;1014ch->newcmd = 0;1015send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,1016ch->cmd, 1, &p1);1017ch->state = STFAX_LINE;1018ch->try_mod = 3;1019}1020break;1021case PSEV_RSP_SILOFF:1022pr_debug("%s: pump stev RSP_SILOFF\n", ch->is->name);1023break;1024case PSEV_RSP_FCERR:1025if (ch->state == STFAX_LINE) {1026pr_debug("%s: pump stev RSP_FCERR try %d\n",1027ch->is->name, ch->try_mod);1028if (ch->try_mod--) {1029send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,1030ch->cmd, 1, &ch->mod);1031break;1032}1033}1034pr_debug("%s: pump stev RSP_FCERR\n", ch->is->name);1035ch->state = STFAX_ESCAPE;1036send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,10370, NULL);1038deliver_status(ch, HW_MOD_FCERROR);1039break;1040default:1041break;1042}1043}10441045void1046mISDNisar_irq(struct isar_hw *isar)1047{1048struct isar_ch *ch;10491050get_irq_infos(isar);1051switch (isar->iis & ISAR_IIS_MSCMSD) {1052case ISAR_IIS_RDATA:1053ch = sel_bch_isar(isar, isar->iis >> 6);1054if (ch)1055isar_rcv_frame(ch);1056else {1057pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n",1058isar->name, isar->iis, isar->cmsb,1059isar->clsb);1060isar->write_reg(isar->hw, ISAR_IIA, 0);1061}1062break;1063case ISAR_IIS_GSTEV:1064isar->write_reg(isar->hw, ISAR_IIA, 0);1065isar->bstat |= isar->cmsb;1066check_send(isar, isar->cmsb);1067break;1068case ISAR_IIS_BSTEV:1069#ifdef ERROR_STATISTIC1070ch = sel_bch_isar(isar, isar->iis >> 6);1071if (ch) {1072if (isar->cmsb == BSTEV_TBO)1073ch->bch.err_tx++;1074if (isar->cmsb == BSTEV_RBO)1075ch->bch.err_rdo++;1076}1077#endif1078pr_debug("%s: Buffer STEV dpath%d msb(%x)\n",1079isar->name, isar->iis>>6, isar->cmsb);1080isar->write_reg(isar->hw, ISAR_IIA, 0);1081break;1082case ISAR_IIS_PSTEV:1083ch = sel_bch_isar(isar, isar->iis >> 6);1084if (ch) {1085rcv_mbox(isar, NULL);1086if (ch->bch.state == ISDN_P_B_MODEM_ASYNC)1087isar_pump_statev_modem(ch, isar->cmsb);1088else if (ch->bch.state == ISDN_P_B_T30_FAX)1089isar_pump_statev_fax(ch, isar->cmsb);1090else if (ch->bch.state == ISDN_P_B_RAW) {1091int tt;1092tt = isar->cmsb | 0x30;1093if (tt == 0x3e)1094tt = '*';1095else if (tt == 0x3f)1096tt = '#';1097else if (tt > '9')1098tt += 7;1099tt |= DTMF_TONE_VAL;1100_queue_data(&ch->bch.ch, PH_CONTROL_IND,1101MISDN_ID_ANY, sizeof(tt), &tt,1102GFP_ATOMIC);1103} else1104pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n",1105isar->name, ch->bch.state,1106isar->cmsb);1107} else {1108pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",1109isar->name, isar->iis, isar->cmsb,1110isar->clsb);1111isar->write_reg(isar->hw, ISAR_IIA, 0);1112}1113break;1114case ISAR_IIS_PSTRSP:1115ch = sel_bch_isar(isar, isar->iis >> 6);1116if (ch) {1117rcv_mbox(isar, NULL);1118isar_pump_status_rsp(ch);1119} else {1120pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",1121isar->name, isar->iis, isar->cmsb,1122isar->clsb);1123isar->write_reg(isar->hw, ISAR_IIA, 0);1124}1125break;1126case ISAR_IIS_DIAG:1127case ISAR_IIS_BSTRSP:1128case ISAR_IIS_IOM2RSP:1129rcv_mbox(isar, NULL);1130break;1131case ISAR_IIS_INVMSG:1132rcv_mbox(isar, NULL);1133pr_debug("%s: invalid msg his:%x\n", isar->name, isar->cmsb);1134break;1135default:1136rcv_mbox(isar, NULL);1137pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n",1138isar->name, isar->iis, isar->cmsb, isar->clsb);1139break;1140}1141}1142EXPORT_SYMBOL(mISDNisar_irq);11431144static void1145ftimer_handler(unsigned long data)1146{1147struct isar_ch *ch = (struct isar_ch *)data;11481149pr_debug("%s: ftimer flags %lx\n", ch->is->name, ch->bch.Flags);1150test_and_clear_bit(FLG_FTI_RUN, &ch->bch.Flags);1151if (test_and_clear_bit(FLG_LL_CONN, &ch->bch.Flags))1152deliver_status(ch, HW_MOD_CONNECT);1153}11541155static void1156setup_pump(struct isar_ch *ch) {1157u8 dps = SET_DPS(ch->dpath);1158u8 ctrl, param[6];11591160switch (ch->bch.state) {1161case ISDN_P_NONE:1162case ISDN_P_B_RAW:1163case ISDN_P_B_HDLC:1164send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, PMOD_BYPASS, 0, NULL);1165break;1166case ISDN_P_B_L2DTMF:1167if (test_bit(FLG_DTMFSEND, &ch->bch.Flags)) {1168param[0] = 5; /* TOA 5 db */1169send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,1170PMOD_DTMF_TRANS, 1, param);1171} else {1172param[0] = 40; /* REL -46 dbm */1173send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,1174PMOD_DTMF, 1, param);1175}1176case ISDN_P_B_MODEM_ASYNC:1177ctrl = PMOD_DATAMODEM;1178if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {1179ctrl |= PCTRL_ORIG;1180param[5] = PV32P6_CTN;1181} else {1182param[5] = PV32P6_ATN;1183}1184param[0] = 6; /* 6 db */1185param[1] = PV32P2_V23R | PV32P2_V22A | PV32P2_V22B |1186PV32P2_V22C | PV32P2_V21 | PV32P2_BEL;1187param[2] = PV32P3_AMOD | PV32P3_V32B | PV32P3_V23B;1188param[3] = PV32P4_UT144;1189param[4] = PV32P5_UT144;1190send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 6, param);1191break;1192case ISDN_P_B_T30_FAX:1193ctrl = PMOD_FAX;1194if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {1195ctrl |= PCTRL_ORIG;1196param[1] = PFAXP2_CTN;1197} else {1198param[1] = PFAXP2_ATN;1199}1200param[0] = 6; /* 6 db */1201send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 2, param);1202ch->state = STFAX_NULL;1203ch->newcmd = 0;1204ch->newmod = 0;1205test_and_set_bit(FLG_FTI_RUN, &ch->bch.Flags);1206break;1207}1208udelay(1000);1209send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);1210udelay(1000);1211}12121213static void1214setup_sart(struct isar_ch *ch) {1215u8 dps = SET_DPS(ch->dpath);1216u8 ctrl, param[2] = {0, 0};12171218switch (ch->bch.state) {1219case ISDN_P_NONE:1220send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_DISABLE,12210, NULL);1222break;1223case ISDN_P_B_RAW:1224case ISDN_P_B_L2DTMF:1225send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_BINARY,12262, param);1227break;1228case ISDN_P_B_HDLC:1229case ISDN_P_B_T30_FAX:1230send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_HDLC,12311, param);1232break;1233case ISDN_P_B_MODEM_ASYNC:1234ctrl = SMODE_V14 | SCTRL_HDMC_BOTH;1235param[0] = S_P1_CHS_8;1236param[1] = S_P2_BFT_DEF;1237send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, ctrl, 2, param);1238break;1239}1240udelay(1000);1241send_mbox(ch->is, dps | ISAR_HIS_BSTREQ, 0, 0, NULL);1242udelay(1000);1243}12441245static void1246setup_iom2(struct isar_ch *ch) {1247u8 dps = SET_DPS(ch->dpath);1248u8 cmsb = IOM_CTRL_ENA, msg[5] = {IOM_P1_TXD, 0, 0, 0, 0};12491250if (ch->bch.nr == 2) {1251msg[1] = 1;1252msg[3] = 1;1253}1254switch (ch->bch.state) {1255case ISDN_P_NONE:1256cmsb = 0;1257/* dummy slot */1258msg[1] = ch->dpath + 2;1259msg[3] = ch->dpath + 2;1260break;1261case ISDN_P_B_RAW:1262case ISDN_P_B_HDLC:1263break;1264case ISDN_P_B_MODEM_ASYNC:1265case ISDN_P_B_T30_FAX:1266cmsb |= IOM_CTRL_RCV;1267case ISDN_P_B_L2DTMF:1268if (test_bit(FLG_DTMFSEND, &ch->bch.Flags))1269cmsb |= IOM_CTRL_RCV;1270cmsb |= IOM_CTRL_ALAW;1271break;1272}1273send_mbox(ch->is, dps | ISAR_HIS_IOM2CFG, cmsb, 5, msg);1274udelay(1000);1275send_mbox(ch->is, dps | ISAR_HIS_IOM2REQ, 0, 0, NULL);1276udelay(1000);1277}12781279static int1280modeisar(struct isar_ch *ch, u32 bprotocol)1281{1282/* Here we are selecting the best datapath for requested protocol */1283if (ch->bch.state == ISDN_P_NONE) { /* New Setup */1284switch (bprotocol) {1285case ISDN_P_NONE: /* init */1286if (!ch->dpath)1287/* no init for dpath 0 */1288return 0;1289test_and_clear_bit(FLG_HDLC, &ch->bch.Flags);1290test_and_clear_bit(FLG_TRANSPARENT, &ch->bch.Flags);1291break;1292case ISDN_P_B_RAW:1293case ISDN_P_B_HDLC:1294/* best is datapath 2 */1295if (!test_and_set_bit(ISAR_DP2_USE, &ch->is->Flags))1296ch->dpath = 2;1297else if (!test_and_set_bit(ISAR_DP1_USE,1298&ch->is->Flags))1299ch->dpath = 1;1300else {1301pr_info("modeisar both pathes in use\n");1302return -EBUSY;1303}1304if (bprotocol == ISDN_P_B_HDLC)1305test_and_set_bit(FLG_HDLC, &ch->bch.Flags);1306else1307test_and_set_bit(FLG_TRANSPARENT,1308&ch->bch.Flags);1309break;1310case ISDN_P_B_MODEM_ASYNC:1311case ISDN_P_B_T30_FAX:1312case ISDN_P_B_L2DTMF:1313/* only datapath 1 */1314if (!test_and_set_bit(ISAR_DP1_USE, &ch->is->Flags))1315ch->dpath = 1;1316else {1317pr_info("%s: ISAR modeisar analog functions"1318"only with DP1\n", ch->is->name);1319return -EBUSY;1320}1321break;1322default:1323pr_info("%s: protocol not known %x\n", ch->is->name,1324bprotocol);1325return -ENOPROTOOPT;1326}1327}1328pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch->is->name,1329ch->bch.nr, ch->dpath, ch->bch.state, bprotocol);1330ch->bch.state = bprotocol;1331setup_pump(ch);1332setup_iom2(ch);1333setup_sart(ch);1334if (ch->bch.state == ISDN_P_NONE) {1335/* Clear resources */1336if (ch->dpath == 1)1337test_and_clear_bit(ISAR_DP1_USE, &ch->is->Flags);1338else if (ch->dpath == 2)1339test_and_clear_bit(ISAR_DP2_USE, &ch->is->Flags);1340ch->dpath = 0;1341ch->is->ctrl(ch->is->hw, HW_DEACT_IND, ch->bch.nr);1342} else1343ch->is->ctrl(ch->is->hw, HW_ACTIVATE_IND, ch->bch.nr);1344return 0;1345}13461347static void1348isar_pump_cmd(struct isar_ch *ch, u32 cmd, u8 para)1349{1350u8 dps = SET_DPS(ch->dpath);1351u8 ctrl = 0, nom = 0, p1 = 0;13521353pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n",1354ch->is->name, cmd, para, ch->bch.state);1355switch (cmd) {1356case HW_MOD_FTM:1357if (ch->state == STFAX_READY) {1358p1 = para;1359ctrl = PCTRL_CMD_FTM;1360nom = 1;1361ch->state = STFAX_LINE;1362ch->cmd = ctrl;1363ch->mod = para;1364ch->newmod = 0;1365ch->newcmd = 0;1366ch->try_mod = 3;1367} else if ((ch->state == STFAX_ACTIV) &&1368(ch->cmd == PCTRL_CMD_FTM) && (ch->mod == para))1369deliver_status(ch, HW_MOD_CONNECT);1370else {1371ch->newmod = para;1372ch->newcmd = PCTRL_CMD_FTM;1373nom = 0;1374ctrl = PCTRL_CMD_ESC;1375ch->state = STFAX_ESCAPE;1376}1377break;1378case HW_MOD_FTH:1379if (ch->state == STFAX_READY) {1380p1 = para;1381ctrl = PCTRL_CMD_FTH;1382nom = 1;1383ch->state = STFAX_LINE;1384ch->cmd = ctrl;1385ch->mod = para;1386ch->newmod = 0;1387ch->newcmd = 0;1388ch->try_mod = 3;1389} else if ((ch->state == STFAX_ACTIV) &&1390(ch->cmd == PCTRL_CMD_FTH) && (ch->mod == para))1391deliver_status(ch, HW_MOD_CONNECT);1392else {1393ch->newmod = para;1394ch->newcmd = PCTRL_CMD_FTH;1395nom = 0;1396ctrl = PCTRL_CMD_ESC;1397ch->state = STFAX_ESCAPE;1398}1399break;1400case HW_MOD_FRM:1401if (ch->state == STFAX_READY) {1402p1 = para;1403ctrl = PCTRL_CMD_FRM;1404nom = 1;1405ch->state = STFAX_LINE;1406ch->cmd = ctrl;1407ch->mod = para;1408ch->newmod = 0;1409ch->newcmd = 0;1410ch->try_mod = 3;1411} else if ((ch->state == STFAX_ACTIV) &&1412(ch->cmd == PCTRL_CMD_FRM) && (ch->mod == para))1413deliver_status(ch, HW_MOD_CONNECT);1414else {1415ch->newmod = para;1416ch->newcmd = PCTRL_CMD_FRM;1417nom = 0;1418ctrl = PCTRL_CMD_ESC;1419ch->state = STFAX_ESCAPE;1420}1421break;1422case HW_MOD_FRH:1423if (ch->state == STFAX_READY) {1424p1 = para;1425ctrl = PCTRL_CMD_FRH;1426nom = 1;1427ch->state = STFAX_LINE;1428ch->cmd = ctrl;1429ch->mod = para;1430ch->newmod = 0;1431ch->newcmd = 0;1432ch->try_mod = 3;1433} else if ((ch->state == STFAX_ACTIV) &&1434(ch->cmd == PCTRL_CMD_FRH) && (ch->mod == para))1435deliver_status(ch, HW_MOD_CONNECT);1436else {1437ch->newmod = para;1438ch->newcmd = PCTRL_CMD_FRH;1439nom = 0;1440ctrl = PCTRL_CMD_ESC;1441ch->state = STFAX_ESCAPE;1442}1443break;1444case PCTRL_CMD_TDTMF:1445p1 = para;1446nom = 1;1447ctrl = PCTRL_CMD_TDTMF;1448break;1449}1450if (ctrl)1451send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, ctrl, nom, &p1);1452}14531454static void1455isar_setup(struct isar_hw *isar)1456{1457u8 msg;1458int i;14591460/* Dpath 1, 2 */1461msg = 61;1462for (i = 0; i < 2; i++) {1463/* Buffer Config */1464send_mbox(isar, (i ? ISAR_HIS_DPS2 : ISAR_HIS_DPS1) |1465ISAR_HIS_P12CFG, 4, 1, &msg);1466isar->ch[i].mml = msg;1467isar->ch[i].bch.state = 0;1468isar->ch[i].dpath = i + 1;1469modeisar(&isar->ch[i], ISDN_P_NONE);1470}1471}14721473static int1474isar_l2l1(struct mISDNchannel *ch, struct sk_buff *skb)1475{1476struct bchannel *bch = container_of(ch, struct bchannel, ch);1477struct isar_ch *ich = container_of(bch, struct isar_ch, bch);1478int ret = -EINVAL;1479struct mISDNhead *hh = mISDN_HEAD_P(skb);1480u32 id, *val;1481u_long flags;14821483switch (hh->prim) {1484case PH_DATA_REQ:1485spin_lock_irqsave(ich->is->hwlock, flags);1486ret = bchannel_senddata(bch, skb);1487if (ret > 0) { /* direct TX */1488id = hh->id; /* skb can be freed */1489ret = 0;1490isar_fill_fifo(ich);1491spin_unlock_irqrestore(ich->is->hwlock, flags);1492if (!test_bit(FLG_TRANSPARENT, &bch->Flags))1493queue_ch_frame(ch, PH_DATA_CNF, id, NULL);1494} else1495spin_unlock_irqrestore(ich->is->hwlock, flags);1496return ret;1497case PH_ACTIVATE_REQ:1498spin_lock_irqsave(ich->is->hwlock, flags);1499if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags))1500ret = modeisar(ich, ch->protocol);1501else1502ret = 0;1503spin_unlock_irqrestore(ich->is->hwlock, flags);1504if (!ret)1505_queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,1506NULL, GFP_KERNEL);1507break;1508case PH_DEACTIVATE_REQ:1509spin_lock_irqsave(ich->is->hwlock, flags);1510mISDN_clear_bchannel(bch);1511modeisar(ich, ISDN_P_NONE);1512spin_unlock_irqrestore(ich->is->hwlock, flags);1513_queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,1514NULL, GFP_KERNEL);1515ret = 0;1516break;1517case PH_CONTROL_REQ:1518val = (u32 *)skb->data;1519pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich->is->name,1520hh->id, *val);1521if ((hh->id == 0) && ((*val & ~DTMF_TONE_MASK) ==1522DTMF_TONE_VAL)) {1523if (bch->state == ISDN_P_B_L2DTMF) {1524char tt = *val & DTMF_TONE_MASK;15251526if (tt == '*')1527tt = 0x1e;1528else if (tt == '#')1529tt = 0x1f;1530else if (tt > '9')1531tt -= 7;1532tt &= 0x1f;1533spin_lock_irqsave(ich->is->hwlock, flags);1534isar_pump_cmd(ich, PCTRL_CMD_TDTMF, tt);1535spin_unlock_irqrestore(ich->is->hwlock, flags);1536} else {1537pr_info("%s: DTMF send wrong protocol %x\n",1538__func__, bch->state);1539return -EINVAL;1540}1541} else if ((hh->id == HW_MOD_FRM) || (hh->id == HW_MOD_FRH) ||1542(hh->id == HW_MOD_FTM) || (hh->id == HW_MOD_FTH)) {1543for (id = 0; id < FAXMODCNT; id++)1544if (faxmodulation[id] == *val)1545break;1546if ((FAXMODCNT > id) &&1547test_bit(FLG_INITIALIZED, &bch->Flags)) {1548pr_debug("%s: isar: new mod\n", ich->is->name);1549isar_pump_cmd(ich, hh->id, *val);1550ret = 0;1551} else {1552pr_info("%s: wrong modulation\n",1553ich->is->name);1554ret = -EINVAL;1555}1556} else if (hh->id == HW_MOD_LASTDATA)1557test_and_set_bit(FLG_DLEETX, &bch->Flags);1558else {1559pr_info("%s: unknown PH_CONTROL_REQ %x\n",1560ich->is->name, hh->id);1561ret = -EINVAL;1562}1563default:1564pr_info("%s: %s unknown prim(%x,%x)\n",1565ich->is->name, __func__, hh->prim, hh->id);1566ret = -EINVAL;1567}1568if (!ret)1569dev_kfree_skb(skb);1570return ret;1571}15721573static int1574channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)1575{1576int ret = 0;15771578switch (cq->op) {1579case MISDN_CTRL_GETOP:1580cq->op = 0;1581break;1582/* Nothing implemented yet */1583case MISDN_CTRL_FILL_EMPTY:1584default:1585pr_info("%s: unknown Op %x\n", __func__, cq->op);1586ret = -EINVAL;1587break;1588}1589return ret;1590}15911592static int1593isar_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)1594{1595struct bchannel *bch = container_of(ch, struct bchannel, ch);1596struct isar_ch *ich = container_of(bch, struct isar_ch, bch);1597int ret = -EINVAL;1598u_long flags;15991600pr_debug("%s: %s cmd:%x %p\n", ich->is->name, __func__, cmd, arg);1601switch (cmd) {1602case CLOSE_CHANNEL:1603test_and_clear_bit(FLG_OPEN, &bch->Flags);1604if (test_bit(FLG_ACTIVE, &bch->Flags)) {1605spin_lock_irqsave(ich->is->hwlock, flags);1606mISDN_freebchannel(bch);1607modeisar(ich, ISDN_P_NONE);1608spin_unlock_irqrestore(ich->is->hwlock, flags);1609} else {1610skb_queue_purge(&bch->rqueue);1611bch->rcount = 0;1612}1613ch->protocol = ISDN_P_NONE;1614ch->peer = NULL;1615module_put(ich->is->owner);1616ret = 0;1617break;1618case CONTROL_CHANNEL:1619ret = channel_bctrl(bch, arg);1620break;1621default:1622pr_info("%s: %s unknown prim(%x)\n",1623ich->is->name, __func__, cmd);1624}1625return ret;1626}16271628static void1629free_isar(struct isar_hw *isar)1630{1631modeisar(&isar->ch[0], ISDN_P_NONE);1632modeisar(&isar->ch[1], ISDN_P_NONE);1633del_timer(&isar->ch[0].ftimer);1634del_timer(&isar->ch[1].ftimer);1635test_and_clear_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);1636test_and_clear_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);1637}16381639static int1640init_isar(struct isar_hw *isar)1641{1642int cnt = 3;16431644while (cnt--) {1645isar->version = ISARVersion(isar);1646if (isar->ch[0].bch.debug & DEBUG_HW)1647pr_notice("%s: Testing version %d (%d time)\n",1648isar->name, isar->version, 3 - cnt);1649if (isar->version == 1)1650break;1651isar->ctrl(isar->hw, HW_RESET_REQ, 0);1652}1653if (isar->version != 1)1654return -EINVAL;1655isar->ch[0].ftimer.function = &ftimer_handler;1656isar->ch[0].ftimer.data = (long)&isar->ch[0];1657init_timer(&isar->ch[0].ftimer);1658test_and_set_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);1659isar->ch[1].ftimer.function = &ftimer_handler;1660isar->ch[1].ftimer.data = (long)&isar->ch[1];1661init_timer(&isar->ch[1].ftimer);1662test_and_set_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);1663return 0;1664}16651666static int1667isar_open(struct isar_hw *isar, struct channel_req *rq)1668{1669struct bchannel *bch;16701671if (rq->adr.channel > 2)1672return -EINVAL;1673if (rq->protocol == ISDN_P_NONE)1674return -EINVAL;1675bch = &isar->ch[rq->adr.channel - 1].bch;1676if (test_and_set_bit(FLG_OPEN, &bch->Flags))1677return -EBUSY; /* b-channel can be only open once */1678test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags);1679bch->ch.protocol = rq->protocol;1680rq->ch = &bch->ch;1681return 0;1682}16831684u321685mISDNisar_init(struct isar_hw *isar, void *hw)1686{1687u32 ret, i;16881689isar->hw = hw;1690for (i = 0; i < 2; i++) {1691isar->ch[i].bch.nr = i + 1;1692mISDN_initbchannel(&isar->ch[i].bch, MAX_DATA_MEM);1693isar->ch[i].bch.ch.nr = i + 1;1694isar->ch[i].bch.ch.send = &isar_l2l1;1695isar->ch[i].bch.ch.ctrl = isar_bctrl;1696isar->ch[i].bch.hw = hw;1697isar->ch[i].is = isar;1698}16991700isar->init = &init_isar;1701isar->release = &free_isar;1702isar->firmware = &load_firmware;1703isar->open = &isar_open;17041705ret = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |1706(1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK)) |1707(1 << (ISDN_P_B_L2DTMF & ISDN_P_B_MASK)) |1708(1 << (ISDN_P_B_MODEM_ASYNC & ISDN_P_B_MASK)) |1709(1 << (ISDN_P_B_T30_FAX & ISDN_P_B_MASK));17101711return ret;1712}1713EXPORT_SYMBOL(mISDNisar_init);17141715static int __init isar_mod_init(void)1716{1717pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV);1718return 0;1719}17201721static void __exit isar_mod_cleanup(void)1722{1723pr_notice("mISDN: ISAR module unloaded\n");1724}1725module_init(isar_mod_init);1726module_exit(isar_mod_cleanup);172717281729