blob: 9deea88c994e28ab521d4565c4ac598a2ef3222e [file] [log] [blame]
Karsten Keilda2272c92009-07-22 20:01:59 +02001/*
2 * mISDNisar.c ISAR (Siemens PSB 7110) specific functions
3 *
4 * Author Karsten Keil (keil@isdn4linux.de)
5 *
6 * Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23/* define this to enable static debug messages, if you kernel supports
24 * dynamic debugging, you should use debugfs for this
25 */
26/* #define DEBUG */
27
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Karsten Keilda2272c92009-07-22 20:01:59 +020029#include <linux/delay.h>
30#include <linux/vmalloc.h>
31#include <linux/mISDNhw.h>
Paul Gortmaker07a97fe2011-08-30 12:08:51 -040032#include <linux/module.h>
Karsten Keilda2272c92009-07-22 20:01:59 +020033#include "isar.h"
34
35#define ISAR_REV "2.1"
36
37MODULE_AUTHOR("Karsten Keil");
38MODULE_LICENSE("GPL v2");
39MODULE_VERSION(ISAR_REV);
40
41#define DEBUG_HW_FIRMWARE_FIFO 0x10000
42
43static const u8 faxmodulation_s[] = "3,24,48,72,73,74,96,97,98,121,122,145,146";
44static const u8 faxmodulation[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121,
Joe Perches475be4d2012-02-19 19:52:38 -080045 122, 145, 146};
Karsten Keilda2272c92009-07-22 20:01:59 +020046#define FAXMODCNT 13
47
48static void isar_setup(struct isar_hw *);
49
50static inline int
51waitforHIA(struct isar_hw *isar, int timeout)
52{
53 int t = timeout;
54 u8 val = isar->read_reg(isar->hw, ISAR_HIA);
55
56 while ((val & 1) && t) {
57 udelay(1);
58 t--;
59 val = isar->read_reg(isar->hw, ISAR_HIA);
60 }
61 pr_debug("%s: HIA after %dus\n", isar->name, timeout - t);
62 return timeout;
63}
64
65/*
66 * send msg to ISAR mailbox
67 * if msg is NULL use isar->buf
68 */
69static int
70send_mbox(struct isar_hw *isar, u8 his, u8 creg, u8 len, u8 *msg)
71{
72 if (!waitforHIA(isar, 1000))
73 return 0;
74 pr_debug("send_mbox(%02x,%02x,%d)\n", his, creg, len);
75 isar->write_reg(isar->hw, ISAR_CTRL_H, creg);
76 isar->write_reg(isar->hw, ISAR_CTRL_L, len);
77 isar->write_reg(isar->hw, ISAR_WADR, 0);
78 if (!msg)
79 msg = isar->buf;
80 if (msg && len) {
81 isar->write_fifo(isar->hw, ISAR_MBOX, msg, len);
82 if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) {
83 int l = 0;
84
85 while (l < (int)len) {
86 hex_dump_to_buffer(msg + l, len - l, 32, 1,
Joe Perches475be4d2012-02-19 19:52:38 -080087 isar->log, 256, 1);
Karsten Keilda2272c92009-07-22 20:01:59 +020088 pr_debug("%s: %s %02x: %s\n", isar->name,
Joe Perches475be4d2012-02-19 19:52:38 -080089 __func__, l, isar->log);
Karsten Keilda2272c92009-07-22 20:01:59 +020090 l += 32;
91 }
92 }
93 }
94 isar->write_reg(isar->hw, ISAR_HIS, his);
95 waitforHIA(isar, 1000);
96 return 1;
97}
98
99/*
100 * receive message from ISAR mailbox
101 * if msg is NULL use isar->buf
102 */
103static void
104rcv_mbox(struct isar_hw *isar, u8 *msg)
105{
106 if (!msg)
107 msg = isar->buf;
108 isar->write_reg(isar->hw, ISAR_RADR, 0);
109 if (msg && isar->clsb) {
110 isar->read_fifo(isar->hw, ISAR_MBOX, msg, isar->clsb);
111 if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) {
112 int l = 0;
113
114 while (l < (int)isar->clsb) {
115 hex_dump_to_buffer(msg + l, isar->clsb - l, 32,
Joe Perches475be4d2012-02-19 19:52:38 -0800116 1, isar->log, 256, 1);
Karsten Keilda2272c92009-07-22 20:01:59 +0200117 pr_debug("%s: %s %02x: %s\n", isar->name,
Joe Perches475be4d2012-02-19 19:52:38 -0800118 __func__, l, isar->log);
Karsten Keilda2272c92009-07-22 20:01:59 +0200119 l += 32;
120 }
121 }
122 }
123 isar->write_reg(isar->hw, ISAR_IIA, 0);
124}
125
126static inline void
127get_irq_infos(struct isar_hw *isar)
128{
129 isar->iis = isar->read_reg(isar->hw, ISAR_IIS);
130 isar->cmsb = isar->read_reg(isar->hw, ISAR_CTRL_H);
131 isar->clsb = isar->read_reg(isar->hw, ISAR_CTRL_L);
132 pr_debug("%s: rcv_mbox(%02x,%02x,%d)\n", isar->name,
Joe Perches475be4d2012-02-19 19:52:38 -0800133 isar->iis, isar->cmsb, isar->clsb);
Karsten Keilda2272c92009-07-22 20:01:59 +0200134}
135
136/*
137 * poll answer message from ISAR mailbox
138 * should be used only with ISAR IRQs disabled before DSP was started
139 *
140 */
141static int
142poll_mbox(struct isar_hw *isar, int maxdelay)
143{
144 int t = maxdelay;
145 u8 irq;
146
147 irq = isar->read_reg(isar->hw, ISAR_IRQBIT);
148 while (t && !(irq & ISAR_IRQSTA)) {
149 udelay(1);
150 t--;
151 }
152 if (t) {
153 get_irq_infos(isar);
154 rcv_mbox(isar, NULL);
155 }
156 pr_debug("%s: pulled %d bytes after %d us\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800157 isar->name, isar->clsb, maxdelay - t);
Karsten Keilda2272c92009-07-22 20:01:59 +0200158 return t;
159}
160
161static int
162ISARVersion(struct isar_hw *isar)
163{
164 int ver;
165
166 /* disable ISAR IRQ */
167 isar->write_reg(isar->hw, ISAR_IRQBIT, 0);
168 isar->buf[0] = ISAR_MSG_HWVER;
169 isar->buf[1] = 0;
170 isar->buf[2] = 1;
171 if (!send_mbox(isar, ISAR_HIS_VNR, 0, 3, NULL))
172 return -1;
173 if (!poll_mbox(isar, 1000))
174 return -2;
175 if (isar->iis == ISAR_IIS_VNR) {
176 if (isar->clsb == 1) {
177 ver = isar->buf[0] & 0xf;
178 return ver;
179 }
180 return -3;
181 }
182 return -4;
183}
184
185static int
186load_firmware(struct isar_hw *isar, const u8 *buf, int size)
187{
188 u32 saved_debug = isar->ch[0].bch.debug;
189 int ret, cnt;
190 u8 nom, noc;
191 u16 left, val, *sp = (u16 *)buf;
192 u8 *mp;
193 u_long flags;
194
195 struct {
196 u16 sadr;
197 u16 len;
198 u16 d_key;
199 } blk_head;
200
201 if (1 != isar->version) {
202 pr_err("%s: ISAR wrong version %d firmware download aborted\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800203 isar->name, isar->version);
Karsten Keilda2272c92009-07-22 20:01:59 +0200204 return -EINVAL;
205 }
206 if (!(saved_debug & DEBUG_HW_FIRMWARE_FIFO))
207 isar->ch[0].bch.debug &= ~DEBUG_HW_BFIFO;
208 pr_debug("%s: load firmware %d words (%d bytes)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800209 isar->name, size / 2, size);
Karsten Keilda2272c92009-07-22 20:01:59 +0200210 cnt = 0;
211 size /= 2;
212 /* disable ISAR IRQ */
213 spin_lock_irqsave(isar->hwlock, flags);
214 isar->write_reg(isar->hw, ISAR_IRQBIT, 0);
215 spin_unlock_irqrestore(isar->hwlock, flags);
216 while (cnt < size) {
217 blk_head.sadr = le16_to_cpu(*sp++);
218 blk_head.len = le16_to_cpu(*sp++);
219 blk_head.d_key = le16_to_cpu(*sp++);
220 cnt += 3;
221 pr_debug("ISAR firmware block (%#x,%d,%#x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800222 blk_head.sadr, blk_head.len, blk_head.d_key & 0xff);
Karsten Keilda2272c92009-07-22 20:01:59 +0200223 left = blk_head.len;
224 if (cnt + left > size) {
225 pr_info("%s: firmware error have %d need %d words\n",
226 isar->name, size, cnt + left);
227 ret = -EINVAL;
228 goto reterrflg;
229 }
230 spin_lock_irqsave(isar->hwlock, flags);
231 if (!send_mbox(isar, ISAR_HIS_DKEY, blk_head.d_key & 0xff,
Joe Perches475be4d2012-02-19 19:52:38 -0800232 0, NULL)) {
Karsten Keilda2272c92009-07-22 20:01:59 +0200233 pr_info("ISAR send_mbox dkey failed\n");
234 ret = -ETIME;
235 goto reterror;
236 }
237 if (!poll_mbox(isar, 1000)) {
238 pr_warning("ISAR poll_mbox dkey failed\n");
239 ret = -ETIME;
240 goto reterror;
241 }
242 spin_unlock_irqrestore(isar->hwlock, flags);
243 if ((isar->iis != ISAR_IIS_DKEY) || isar->cmsb || isar->clsb) {
244 pr_info("ISAR wrong dkey response (%x,%x,%x)\n",
245 isar->iis, isar->cmsb, isar->clsb);
246 ret = 1;
247 goto reterrflg;
248 }
249 while (left > 0) {
250 if (left > 126)
251 noc = 126;
252 else
253 noc = left;
254 nom = (2 * noc) + 3;
255 mp = isar->buf;
256 /* the ISAR is big endian */
257 *mp++ = blk_head.sadr >> 8;
258 *mp++ = blk_head.sadr & 0xFF;
259 left -= noc;
260 cnt += noc;
261 *mp++ = noc;
262 pr_debug("%s: load %3d words at %04x\n", isar->name,
Joe Perches475be4d2012-02-19 19:52:38 -0800263 noc, blk_head.sadr);
Karsten Keilda2272c92009-07-22 20:01:59 +0200264 blk_head.sadr += noc;
265 while (noc) {
266 val = le16_to_cpu(*sp++);
267 *mp++ = val >> 8;
Joe Perchesad65ffd2010-11-14 17:04:26 +0000268 *mp++ = val & 0xFF;
Karsten Keilda2272c92009-07-22 20:01:59 +0200269 noc--;
270 }
271 spin_lock_irqsave(isar->hwlock, flags);
272 if (!send_mbox(isar, ISAR_HIS_FIRM, 0, nom, NULL)) {
273 pr_info("ISAR send_mbox prog failed\n");
274 ret = -ETIME;
275 goto reterror;
276 }
277 if (!poll_mbox(isar, 1000)) {
278 pr_info("ISAR poll_mbox prog failed\n");
279 ret = -ETIME;
280 goto reterror;
281 }
282 spin_unlock_irqrestore(isar->hwlock, flags);
283 if ((isar->iis != ISAR_IIS_FIRM) ||
284 isar->cmsb || isar->clsb) {
285 pr_info("ISAR wrong prog response (%x,%x,%x)\n",
286 isar->iis, isar->cmsb, isar->clsb);
287 ret = -EIO;
288 goto reterrflg;
289 }
290 }
291 pr_debug("%s: ISAR firmware block %d words loaded\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800292 isar->name, blk_head.len);
Karsten Keilda2272c92009-07-22 20:01:59 +0200293 }
294 isar->ch[0].bch.debug = saved_debug;
295 /* 10ms delay */
296 cnt = 10;
297 while (cnt--)
298 mdelay(1);
299 isar->buf[0] = 0xff;
300 isar->buf[1] = 0xfe;
301 isar->bstat = 0;
302 spin_lock_irqsave(isar->hwlock, flags);
303 if (!send_mbox(isar, ISAR_HIS_STDSP, 0, 2, NULL)) {
304 pr_info("ISAR send_mbox start dsp failed\n");
305 ret = -ETIME;
306 goto reterror;
307 }
308 if (!poll_mbox(isar, 1000)) {
309 pr_info("ISAR poll_mbox start dsp failed\n");
310 ret = -ETIME;
311 goto reterror;
312 }
313 if ((isar->iis != ISAR_IIS_STDSP) || isar->cmsb || isar->clsb) {
314 pr_info("ISAR wrong start dsp response (%x,%x,%x)\n",
315 isar->iis, isar->cmsb, isar->clsb);
316 ret = -EIO;
317 goto reterror;
318 } else
319 pr_debug("%s: ISAR start dsp success\n", isar->name);
320
321 /* NORMAL mode entered */
322 /* Enable IRQs of ISAR */
323 isar->write_reg(isar->hw, ISAR_IRQBIT, ISAR_IRQSTA);
324 spin_unlock_irqrestore(isar->hwlock, flags);
325 cnt = 1000; /* max 1s */
326 while ((!isar->bstat) && cnt) {
327 mdelay(1);
328 cnt--;
329 }
330 if (!cnt) {
331 pr_info("ISAR no general status event received\n");
332 ret = -ETIME;
333 goto reterrflg;
334 } else
335 pr_debug("%s: ISAR general status event %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800336 isar->name, isar->bstat);
Karsten Keilda2272c92009-07-22 20:01:59 +0200337 /* 10ms delay */
338 cnt = 10;
339 while (cnt--)
340 mdelay(1);
341 isar->iis = 0;
342 spin_lock_irqsave(isar->hwlock, flags);
343 if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_STST, 0, NULL)) {
344 pr_info("ISAR send_mbox self tst failed\n");
345 ret = -ETIME;
346 goto reterror;
347 }
348 spin_unlock_irqrestore(isar->hwlock, flags);
349 cnt = 10000; /* max 100 ms */
350 while ((isar->iis != ISAR_IIS_DIAG) && cnt) {
351 udelay(10);
352 cnt--;
353 }
354 mdelay(1);
355 if (!cnt) {
356 pr_info("ISAR no self tst response\n");
357 ret = -ETIME;
358 goto reterrflg;
359 }
360 if ((isar->cmsb == ISAR_CTRL_STST) && (isar->clsb == 1)
361 && (isar->buf[0] == 0))
362 pr_debug("%s: ISAR selftest OK\n", isar->name);
363 else {
364 pr_info("ISAR selftest not OK %x/%x/%x\n",
365 isar->cmsb, isar->clsb, isar->buf[0]);
366 ret = -EIO;
367 goto reterrflg;
368 }
369 spin_lock_irqsave(isar->hwlock, flags);
370 isar->iis = 0;
371 if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_SWVER, 0, NULL)) {
372 pr_info("ISAR RQST SVN failed\n");
373 ret = -ETIME;
374 goto reterror;
375 }
376 spin_unlock_irqrestore(isar->hwlock, flags);
377 cnt = 30000; /* max 300 ms */
378 while ((isar->iis != ISAR_IIS_DIAG) && cnt) {
379 udelay(10);
380 cnt--;
381 }
382 mdelay(1);
383 if (!cnt) {
384 pr_info("ISAR no SVN response\n");
385 ret = -ETIME;
386 goto reterrflg;
387 } else {
388 if ((isar->cmsb == ISAR_CTRL_SWVER) && (isar->clsb == 1)) {
389 pr_notice("%s: ISAR software version %#x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800390 isar->name, isar->buf[0]);
Karsten Keilda2272c92009-07-22 20:01:59 +0200391 } else {
392 pr_info("%s: ISAR wrong swver response (%x,%x)"
393 " cnt(%d)\n", isar->name, isar->cmsb,
394 isar->clsb, cnt);
395 ret = -EIO;
396 goto reterrflg;
397 }
398 }
399 spin_lock_irqsave(isar->hwlock, flags);
400 isar_setup(isar);
401 spin_unlock_irqrestore(isar->hwlock, flags);
402 ret = 0;
403reterrflg:
404 spin_lock_irqsave(isar->hwlock, flags);
405reterror:
406 isar->ch[0].bch.debug = saved_debug;
407 if (ret)
408 /* disable ISAR IRQ */
409 isar->write_reg(isar->hw, ISAR_IRQBIT, 0);
410 spin_unlock_irqrestore(isar->hwlock, flags);
411 return ret;
412}
413
414static inline void
415deliver_status(struct isar_ch *ch, int status)
416{
417 pr_debug("%s: HL->LL FAXIND %x\n", ch->is->name, status);
418 _queue_data(&ch->bch.ch, PH_CONTROL_IND, status, 0, NULL, GFP_ATOMIC);
419}
420
421static inline void
422isar_rcv_frame(struct isar_ch *ch)
423{
424 u8 *ptr;
425
426 if (!ch->is->clsb) {
427 pr_debug("%s; ISAR zero len frame\n", ch->is->name);
428 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
429 return;
430 }
431 switch (ch->bch.state) {
432 case ISDN_P_NONE:
433 pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800434 ch->is->name, ch->is->iis, ch->is->cmsb, ch->is->clsb);
Karsten Keilda2272c92009-07-22 20:01:59 +0200435 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
436 break;
437 case ISDN_P_B_RAW:
438 case ISDN_P_B_L2DTMF:
439 case ISDN_P_B_MODEM_ASYNC:
440 if (!ch->bch.rx_skb) {
441 ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,
Joe Perches475be4d2012-02-19 19:52:38 -0800442 GFP_ATOMIC);
Karsten Keilda2272c92009-07-22 20:01:59 +0200443 if (unlikely(!ch->bch.rx_skb)) {
444 pr_info("%s: B receive out of memory\n",
445 ch->is->name);
446 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
447 break;
448 }
449 }
450 rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));
451 recv_Bchannel(&ch->bch, 0);
452 break;
453 case ISDN_P_B_HDLC:
454 if (!ch->bch.rx_skb) {
455 ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,
Joe Perches475be4d2012-02-19 19:52:38 -0800456 GFP_ATOMIC);
Karsten Keilda2272c92009-07-22 20:01:59 +0200457 if (unlikely(!ch->bch.rx_skb)) {
458 pr_info("%s: B receive out of memory\n",
459 ch->is->name);
460 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
461 break;
462 }
463 }
464 if ((ch->bch.rx_skb->len + ch->is->clsb) >
465 (ch->bch.maxlen + 2)) {
466 pr_debug("%s: incoming packet too large\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800467 ch->is->name);
Karsten Keilda2272c92009-07-22 20:01:59 +0200468 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
469 skb_trim(ch->bch.rx_skb, 0);
470 break;
471 }
472 if (ch->is->cmsb & HDLC_ERROR) {
473 pr_debug("%s: ISAR frame error %x len %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800474 ch->is->name, ch->is->cmsb, ch->is->clsb);
Karsten Keilda2272c92009-07-22 20:01:59 +0200475#ifdef ERROR_STATISTIC
476 if (ch->is->cmsb & HDLC_ERR_RER)
477 ch->bch.err_inv++;
478 if (ch->is->cmsb & HDLC_ERR_CER)
479 ch->bch.err_crc++;
480#endif
481 skb_trim(ch->bch.rx_skb, 0);
482 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
483 break;
484 }
485 if (ch->is->cmsb & HDLC_FSD)
486 skb_trim(ch->bch.rx_skb, 0);
487 ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);
488 rcv_mbox(ch->is, ptr);
489 if (ch->is->cmsb & HDLC_FED) {
490 if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */
491 pr_debug("%s: ISAR frame to short %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800492 ch->is->name, ch->bch.rx_skb->len);
Karsten Keilda2272c92009-07-22 20:01:59 +0200493 skb_trim(ch->bch.rx_skb, 0);
494 break;
495 }
496 skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);
497 recv_Bchannel(&ch->bch, 0);
498 }
499 break;
500 case ISDN_P_B_T30_FAX:
501 if (ch->state != STFAX_ACTIV) {
502 pr_debug("%s: isar_rcv_frame: not ACTIV\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800503 ch->is->name);
Karsten Keilda2272c92009-07-22 20:01:59 +0200504 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
505 if (ch->bch.rx_skb)
506 skb_trim(ch->bch.rx_skb, 0);
507 break;
508 }
509 if (!ch->bch.rx_skb) {
510 ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,
Joe Perches475be4d2012-02-19 19:52:38 -0800511 GFP_ATOMIC);
Karsten Keilda2272c92009-07-22 20:01:59 +0200512 if (unlikely(!ch->bch.rx_skb)) {
513 pr_info("%s: B receive out of memory\n",
514 __func__);
515 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
516 break;
517 }
518 }
519 if (ch->cmd == PCTRL_CMD_FRM) {
520 rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));
521 pr_debug("%s: isar_rcv_frame: %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800522 ch->is->name, ch->bch.rx_skb->len);
Karsten Keilda2272c92009-07-22 20:01:59 +0200523 if (ch->is->cmsb & SART_NMD) { /* ABORT */
524 pr_debug("%s: isar_rcv_frame: no more data\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800525 ch->is->name);
Karsten Keilda2272c92009-07-22 20:01:59 +0200526 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
527 send_mbox(ch->is, SET_DPS(ch->dpath) |
Joe Perches475be4d2012-02-19 19:52:38 -0800528 ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,
529 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +0200530 ch->state = STFAX_ESCAPE;
531 /* set_skb_flag(skb, DF_NOMOREDATA); */
532 }
533 recv_Bchannel(&ch->bch, 0);
534 if (ch->is->cmsb & SART_NMD)
535 deliver_status(ch, HW_MOD_NOCARR);
536 break;
537 }
538 if (ch->cmd != PCTRL_CMD_FRH) {
539 pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800540 ch->is->name, ch->cmd);
Karsten Keilda2272c92009-07-22 20:01:59 +0200541 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
542 if (ch->bch.rx_skb)
543 skb_trim(ch->bch.rx_skb, 0);
544 break;
545 }
546 /* PCTRL_CMD_FRH */
547 if ((ch->bch.rx_skb->len + ch->is->clsb) >
548 (ch->bch.maxlen + 2)) {
549 pr_info("%s: %s incoming packet too large\n",
550 ch->is->name, __func__);
551 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
552 skb_trim(ch->bch.rx_skb, 0);
553 break;
554 } else if (ch->is->cmsb & HDLC_ERROR) {
555 pr_info("%s: ISAR frame error %x len %d\n",
556 ch->is->name, ch->is->cmsb, ch->is->clsb);
557 skb_trim(ch->bch.rx_skb, 0);
558 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
559 break;
560 }
561 if (ch->is->cmsb & HDLC_FSD)
562 skb_trim(ch->bch.rx_skb, 0);
563 ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);
564 rcv_mbox(ch->is, ptr);
565 if (ch->is->cmsb & HDLC_FED) {
566 if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */
567 pr_info("%s: ISAR frame to short %d\n",
568 ch->is->name, ch->bch.rx_skb->len);
569 skb_trim(ch->bch.rx_skb, 0);
570 break;
571 }
572 skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);
573 recv_Bchannel(&ch->bch, 0);
574 }
575 if (ch->is->cmsb & SART_NMD) { /* ABORT */
576 pr_debug("%s: isar_rcv_frame: no more data\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800577 ch->is->name);
Karsten Keilda2272c92009-07-22 20:01:59 +0200578 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
579 if (ch->bch.rx_skb)
580 skb_trim(ch->bch.rx_skb, 0);
581 send_mbox(ch->is, SET_DPS(ch->dpath) |
Joe Perches475be4d2012-02-19 19:52:38 -0800582 ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC, 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +0200583 ch->state = STFAX_ESCAPE;
584 deliver_status(ch, HW_MOD_NOCARR);
585 }
586 break;
587 default:
588 pr_info("isar_rcv_frame protocol (%x)error\n", ch->bch.state);
589 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
590 break;
591 }
592}
593
594static void
595isar_fill_fifo(struct isar_ch *ch)
596{
597 int count;
598 u8 msb;
599 u8 *ptr;
600
601 pr_debug("%s: ch%d tx_skb %p tx_idx %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800602 ch->is->name, ch->bch.nr, ch->bch.tx_skb, ch->bch.tx_idx);
Karsten Keilda2272c92009-07-22 20:01:59 +0200603 if (!ch->bch.tx_skb)
604 return;
605 count = ch->bch.tx_skb->len - ch->bch.tx_idx;
606 if (count <= 0)
607 return;
608 if (!(ch->is->bstat &
Joe Perches475be4d2012-02-19 19:52:38 -0800609 (ch->dpath == 1 ? BSTAT_RDM1 : BSTAT_RDM2)))
Karsten Keilda2272c92009-07-22 20:01:59 +0200610 return;
611 if (count > ch->mml) {
612 msb = 0;
613 count = ch->mml;
614 } else {
615 msb = HDLC_FED;
616 }
617 ptr = ch->bch.tx_skb->data + ch->bch.tx_idx;
618 if (!ch->bch.tx_idx) {
619 pr_debug("%s: frame start\n", ch->is->name);
620 if ((ch->bch.state == ISDN_P_B_T30_FAX) &&
Joe Perches475be4d2012-02-19 19:52:38 -0800621 (ch->cmd == PCTRL_CMD_FTH)) {
Karsten Keilda2272c92009-07-22 20:01:59 +0200622 if (count > 1) {
623 if ((ptr[0] == 0xff) && (ptr[1] == 0x13)) {
624 /* last frame */
625 test_and_set_bit(FLG_LASTDATA,
Joe Perches475be4d2012-02-19 19:52:38 -0800626 &ch->bch.Flags);
Karsten Keilda2272c92009-07-22 20:01:59 +0200627 pr_debug("%s: set LASTDATA\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800628 ch->is->name);
Karsten Keilda2272c92009-07-22 20:01:59 +0200629 if (msb == HDLC_FED)
630 test_and_set_bit(FLG_DLEETX,
Joe Perches475be4d2012-02-19 19:52:38 -0800631 &ch->bch.Flags);
Karsten Keilda2272c92009-07-22 20:01:59 +0200632 }
633 }
634 }
635 msb |= HDLC_FST;
636 }
637 ch->bch.tx_idx += count;
638 switch (ch->bch.state) {
639 case ISDN_P_NONE:
640 pr_info("%s: wrong protocol 0\n", __func__);
641 break;
642 case ISDN_P_B_RAW:
643 case ISDN_P_B_L2DTMF:
644 case ISDN_P_B_MODEM_ASYNC:
645 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
Joe Perches475be4d2012-02-19 19:52:38 -0800646 0, count, ptr);
Karsten Keilda2272c92009-07-22 20:01:59 +0200647 break;
648 case ISDN_P_B_HDLC:
649 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
Joe Perches475be4d2012-02-19 19:52:38 -0800650 msb, count, ptr);
Karsten Keilda2272c92009-07-22 20:01:59 +0200651 break;
652 case ISDN_P_B_T30_FAX:
653 if (ch->state != STFAX_ACTIV)
654 pr_debug("%s: not ACTIV\n", ch->is->name);
655 else if (ch->cmd == PCTRL_CMD_FTH)
656 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
Joe Perches475be4d2012-02-19 19:52:38 -0800657 msb, count, ptr);
Karsten Keilda2272c92009-07-22 20:01:59 +0200658 else if (ch->cmd == PCTRL_CMD_FTM)
659 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
Joe Perches475be4d2012-02-19 19:52:38 -0800660 0, count, ptr);
Karsten Keilda2272c92009-07-22 20:01:59 +0200661 else
662 pr_debug("%s: not FTH/FTM\n", ch->is->name);
663 break;
664 default:
665 pr_info("%s: protocol(%x) error\n",
666 __func__, ch->bch.state);
667 break;
668 }
669}
670
671static inline struct isar_ch *
672sel_bch_isar(struct isar_hw *isar, u8 dpath)
673{
674 struct isar_ch *base = &isar->ch[0];
675
676 if ((!dpath) || (dpath > 2))
677 return NULL;
678 if (base->dpath == dpath)
679 return base;
680 base++;
681 if (base->dpath == dpath)
682 return base;
683 return NULL;
684}
685
686static void
687send_next(struct isar_ch *ch)
688{
689 pr_debug("%s: %s ch%d tx_skb %p tx_idx %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800690 ch->is->name, __func__, ch->bch.nr,
691 ch->bch.tx_skb, ch->bch.tx_idx);
Karsten Keilda2272c92009-07-22 20:01:59 +0200692 if (ch->bch.state == ISDN_P_B_T30_FAX) {
693 if (ch->cmd == PCTRL_CMD_FTH) {
694 if (test_bit(FLG_LASTDATA, &ch->bch.Flags)) {
695 pr_debug("set NMD_DATA\n");
696 test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);
697 }
698 } else if (ch->cmd == PCTRL_CMD_FTM) {
699 if (test_bit(FLG_DLEETX, &ch->bch.Flags)) {
700 test_and_set_bit(FLG_LASTDATA, &ch->bch.Flags);
701 test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);
702 }
703 }
704 }
Karsten Keil8bfddfb2012-05-15 23:51:02 +0000705 if (ch->bch.tx_skb)
Karsten Keilda2272c92009-07-22 20:01:59 +0200706 dev_kfree_skb(ch->bch.tx_skb);
Karsten Keil8bfddfb2012-05-15 23:51:02 +0000707 if (get_next_bframe(&ch->bch)) {
Karsten Keilda2272c92009-07-22 20:01:59 +0200708 isar_fill_fifo(ch);
Karsten Keil8bfddfb2012-05-15 23:51:02 +0000709 } else {
Karsten Keilda2272c92009-07-22 20:01:59 +0200710 if (test_and_clear_bit(FLG_DLEETX, &ch->bch.Flags)) {
711 if (test_and_clear_bit(FLG_LASTDATA,
Joe Perches475be4d2012-02-19 19:52:38 -0800712 &ch->bch.Flags)) {
Karsten Keilda2272c92009-07-22 20:01:59 +0200713 if (test_and_clear_bit(FLG_NMD_DATA,
Joe Perches475be4d2012-02-19 19:52:38 -0800714 &ch->bch.Flags)) {
Karsten Keilda2272c92009-07-22 20:01:59 +0200715 u8 zd = 0;
716 send_mbox(ch->is, SET_DPS(ch->dpath) |
Joe Perches475be4d2012-02-19 19:52:38 -0800717 ISAR_HIS_SDATA, 0x01, 1, &zd);
Karsten Keilda2272c92009-07-22 20:01:59 +0200718 }
719 test_and_set_bit(FLG_LL_OK, &ch->bch.Flags);
720 } else {
721 deliver_status(ch, HW_MOD_CONNECT);
722 }
723 }
724 }
725}
726
727static void
728check_send(struct isar_hw *isar, u8 rdm)
729{
730 struct isar_ch *ch;
731
732 pr_debug("%s: rdm %x\n", isar->name, rdm);
733 if (rdm & BSTAT_RDM1) {
734 ch = sel_bch_isar(isar, 1);
735 if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {
736 if (ch->bch.tx_skb && (ch->bch.tx_skb->len >
Joe Perches475be4d2012-02-19 19:52:38 -0800737 ch->bch.tx_idx))
Karsten Keilda2272c92009-07-22 20:01:59 +0200738 isar_fill_fifo(ch);
739 else
740 send_next(ch);
741 }
742 }
743 if (rdm & BSTAT_RDM2) {
744 ch = sel_bch_isar(isar, 2);
745 if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {
746 if (ch->bch.tx_skb && (ch->bch.tx_skb->len >
Joe Perches475be4d2012-02-19 19:52:38 -0800747 ch->bch.tx_idx))
Karsten Keilda2272c92009-07-22 20:01:59 +0200748 isar_fill_fifo(ch);
749 else
750 send_next(ch);
751 }
752 }
753}
754
755const char *dmril[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",
Joe Perches475be4d2012-02-19 19:52:38 -0800756 "300", "600", "1200", "2400", "4800", "7200",
757 "9600nt", "9600t", "12000", "14400", "WRONG"};
Karsten Keilda2272c92009-07-22 20:01:59 +0200758const char *dmrim[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",
Joe Perches475be4d2012-02-19 19:52:38 -0800759 "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};
Karsten Keilda2272c92009-07-22 20:01:59 +0200760
761static void
762isar_pump_status_rsp(struct isar_ch *ch) {
763 u8 ril = ch->is->buf[0];
764 u8 rim;
765
766 if (!test_and_clear_bit(ISAR_RATE_REQ, &ch->is->Flags))
767 return;
768 if (ril > 14) {
769 pr_info("%s: wrong pstrsp ril=%d\n", ch->is->name, ril);
770 ril = 15;
771 }
772 switch (ch->is->buf[1]) {
773 case 0:
774 rim = 0;
775 break;
776 case 0x20:
777 rim = 2;
778 break;
779 case 0x40:
780 rim = 3;
781 break;
782 case 0x41:
783 rim = 4;
784 break;
785 case 0x51:
786 rim = 5;
787 break;
788 case 0x61:
789 rim = 6;
790 break;
791 case 0x71:
792 rim = 7;
793 break;
794 case 0x82:
795 rim = 8;
796 break;
797 case 0x92:
798 rim = 9;
799 break;
800 case 0xa2:
801 rim = 10;
802 break;
803 default:
804 rim = 1;
805 break;
806 }
807 sprintf(ch->conmsg, "%s %s", dmril[ril], dmrim[rim]);
808 pr_debug("%s: pump strsp %s\n", ch->is->name, ch->conmsg);
809}
810
811static void
812isar_pump_statev_modem(struct isar_ch *ch, u8 devt) {
813 u8 dps = SET_DPS(ch->dpath);
814
815 switch (devt) {
816 case PSEV_10MS_TIMER:
817 pr_debug("%s: pump stev TIMER\n", ch->is->name);
818 break;
819 case PSEV_CON_ON:
820 pr_debug("%s: pump stev CONNECT\n", ch->is->name);
821 deliver_status(ch, HW_MOD_CONNECT);
822 break;
823 case PSEV_CON_OFF:
824 pr_debug("%s: pump stev NO CONNECT\n", ch->is->name);
825 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
826 deliver_status(ch, HW_MOD_NOCARR);
827 break;
828 case PSEV_V24_OFF:
829 pr_debug("%s: pump stev V24 OFF\n", ch->is->name);
830 break;
831 case PSEV_CTS_ON:
832 pr_debug("%s: pump stev CTS ON\n", ch->is->name);
833 break;
834 case PSEV_CTS_OFF:
835 pr_debug("%s pump stev CTS OFF\n", ch->is->name);
836 break;
837 case PSEV_DCD_ON:
838 pr_debug("%s: pump stev CARRIER ON\n", ch->is->name);
839 test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);
840 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
841 break;
842 case PSEV_DCD_OFF:
843 pr_debug("%s: pump stev CARRIER OFF\n", ch->is->name);
844 break;
845 case PSEV_DSR_ON:
846 pr_debug("%s: pump stev DSR ON\n", ch->is->name);
847 break;
848 case PSEV_DSR_OFF:
849 pr_debug("%s: pump stev DSR_OFF\n", ch->is->name);
850 break;
851 case PSEV_REM_RET:
852 pr_debug("%s: pump stev REMOTE RETRAIN\n", ch->is->name);
853 break;
854 case PSEV_REM_REN:
855 pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch->is->name);
856 break;
857 case PSEV_GSTN_CLR:
858 pr_debug("%s: pump stev GSTN CLEAR\n", ch->is->name);
859 break;
860 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200861 pr_info("u%s: unknown pump stev %x\n", ch->is->name, devt);
Karsten Keilda2272c92009-07-22 20:01:59 +0200862 break;
863 }
864}
865
866static void
867isar_pump_statev_fax(struct isar_ch *ch, u8 devt) {
868 u8 dps = SET_DPS(ch->dpath);
869 u8 p1;
870
871 switch (devt) {
872 case PSEV_10MS_TIMER:
873 pr_debug("%s: pump stev TIMER\n", ch->is->name);
874 break;
875 case PSEV_RSP_READY:
876 pr_debug("%s: pump stev RSP_READY\n", ch->is->name);
877 ch->state = STFAX_READY;
878 deliver_status(ch, HW_MOD_READY);
879#ifdef AUTOCON
880 if (test_bit(BC_FLG_ORIG, &ch->bch.Flags))
881 isar_pump_cmd(bch, HW_MOD_FRH, 3);
882 else
883 isar_pump_cmd(bch, HW_MOD_FTH, 3);
884#endif
885 break;
886 case PSEV_LINE_TX_H:
887 if (ch->state == STFAX_LINE) {
888 pr_debug("%s: pump stev LINE_TX_H\n", ch->is->name);
889 ch->state = STFAX_CONT;
890 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -0800891 PCTRL_CMD_CONT, 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +0200892 } else {
893 pr_debug("%s: pump stev LINE_TX_H wrong st %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800894 ch->is->name, ch->state);
Karsten Keilda2272c92009-07-22 20:01:59 +0200895 }
896 break;
897 case PSEV_LINE_RX_H:
898 if (ch->state == STFAX_LINE) {
899 pr_debug("%s: pump stev LINE_RX_H\n", ch->is->name);
900 ch->state = STFAX_CONT;
901 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -0800902 PCTRL_CMD_CONT, 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +0200903 } else {
904 pr_debug("%s: pump stev LINE_RX_H wrong st %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800905 ch->is->name, ch->state);
Karsten Keilda2272c92009-07-22 20:01:59 +0200906 }
907 break;
908 case PSEV_LINE_TX_B:
909 if (ch->state == STFAX_LINE) {
910 pr_debug("%s: pump stev LINE_TX_B\n", ch->is->name);
911 ch->state = STFAX_CONT;
912 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -0800913 PCTRL_CMD_CONT, 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +0200914 } else {
915 pr_debug("%s: pump stev LINE_TX_B wrong st %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800916 ch->is->name, ch->state);
Karsten Keilda2272c92009-07-22 20:01:59 +0200917 }
918 break;
919 case PSEV_LINE_RX_B:
920 if (ch->state == STFAX_LINE) {
921 pr_debug("%s: pump stev LINE_RX_B\n", ch->is->name);
922 ch->state = STFAX_CONT;
923 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -0800924 PCTRL_CMD_CONT, 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +0200925 } else {
926 pr_debug("%s: pump stev LINE_RX_B wrong st %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800927 ch->is->name, ch->state);
Karsten Keilda2272c92009-07-22 20:01:59 +0200928 }
929 break;
930 case PSEV_RSP_CONN:
931 if (ch->state == STFAX_CONT) {
932 pr_debug("%s: pump stev RSP_CONN\n", ch->is->name);
933 ch->state = STFAX_ACTIV;
934 test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);
935 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
936 if (ch->cmd == PCTRL_CMD_FTH) {
937 int delay = (ch->mod == 3) ? 1000 : 200;
938 /* 1s (200 ms) Flags before data */
939 if (test_and_set_bit(FLG_FTI_RUN,
Joe Perches475be4d2012-02-19 19:52:38 -0800940 &ch->bch.Flags))
Karsten Keilda2272c92009-07-22 20:01:59 +0200941 del_timer(&ch->ftimer);
942 ch->ftimer.expires =
Joe Perches475be4d2012-02-19 19:52:38 -0800943 jiffies + ((delay * HZ) / 1000);
Karsten Keilda2272c92009-07-22 20:01:59 +0200944 test_and_set_bit(FLG_LL_CONN,
Joe Perches475be4d2012-02-19 19:52:38 -0800945 &ch->bch.Flags);
Karsten Keilda2272c92009-07-22 20:01:59 +0200946 add_timer(&ch->ftimer);
947 } else {
948 deliver_status(ch, HW_MOD_CONNECT);
949 }
950 } else {
951 pr_debug("%s: pump stev RSP_CONN wrong st %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800952 ch->is->name, ch->state);
Karsten Keilda2272c92009-07-22 20:01:59 +0200953 }
954 break;
955 case PSEV_FLAGS_DET:
956 pr_debug("%s: pump stev FLAGS_DET\n", ch->is->name);
957 break;
958 case PSEV_RSP_DISC:
959 pr_debug("%s: pump stev RSP_DISC state(%d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800960 ch->is->name, ch->state);
Karsten Keilda2272c92009-07-22 20:01:59 +0200961 if (ch->state == STFAX_ESCAPE) {
962 p1 = 5;
963 switch (ch->newcmd) {
964 case 0:
965 ch->state = STFAX_READY;
966 break;
967 case PCTRL_CMD_FTM:
968 p1 = 2;
969 case PCTRL_CMD_FTH:
970 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -0800971 PCTRL_CMD_SILON, 1, &p1);
Karsten Keilda2272c92009-07-22 20:01:59 +0200972 ch->state = STFAX_SILDET;
973 break;
974 case PCTRL_CMD_FRH:
975 case PCTRL_CMD_FRM:
976 ch->mod = ch->newmod;
977 p1 = ch->newmod;
978 ch->newmod = 0;
979 ch->cmd = ch->newcmd;
980 ch->newcmd = 0;
981 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -0800982 ch->cmd, 1, &p1);
Karsten Keilda2272c92009-07-22 20:01:59 +0200983 ch->state = STFAX_LINE;
984 ch->try_mod = 3;
985 break;
986 default:
987 pr_debug("%s: RSP_DISC unknown newcmd %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800988 ch->is->name, ch->newcmd);
Karsten Keilda2272c92009-07-22 20:01:59 +0200989 break;
990 }
991 } else if (ch->state == STFAX_ACTIV) {
992 if (test_and_clear_bit(FLG_LL_OK, &ch->bch.Flags))
993 deliver_status(ch, HW_MOD_OK);
994 else if (ch->cmd == PCTRL_CMD_FRM)
995 deliver_status(ch, HW_MOD_NOCARR);
996 else
997 deliver_status(ch, HW_MOD_FCERROR);
998 ch->state = STFAX_READY;
999 } else if (ch->state != STFAX_SILDET) {
1000 /* ignore in STFAX_SILDET */
1001 ch->state = STFAX_READY;
1002 deliver_status(ch, HW_MOD_FCERROR);
1003 }
1004 break;
1005 case PSEV_RSP_SILDET:
1006 pr_debug("%s: pump stev RSP_SILDET\n", ch->is->name);
1007 if (ch->state == STFAX_SILDET) {
1008 ch->mod = ch->newmod;
1009 p1 = ch->newmod;
1010 ch->newmod = 0;
1011 ch->cmd = ch->newcmd;
1012 ch->newcmd = 0;
1013 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -08001014 ch->cmd, 1, &p1);
Karsten Keilda2272c92009-07-22 20:01:59 +02001015 ch->state = STFAX_LINE;
1016 ch->try_mod = 3;
1017 }
1018 break;
1019 case PSEV_RSP_SILOFF:
1020 pr_debug("%s: pump stev RSP_SILOFF\n", ch->is->name);
1021 break;
1022 case PSEV_RSP_FCERR:
1023 if (ch->state == STFAX_LINE) {
1024 pr_debug("%s: pump stev RSP_FCERR try %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001025 ch->is->name, ch->try_mod);
Karsten Keilda2272c92009-07-22 20:01:59 +02001026 if (ch->try_mod--) {
1027 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
Joe Perches475be4d2012-02-19 19:52:38 -08001028 ch->cmd, 1, &ch->mod);
Karsten Keilda2272c92009-07-22 20:01:59 +02001029 break;
1030 }
1031 }
1032 pr_debug("%s: pump stev RSP_FCERR\n", ch->is->name);
1033 ch->state = STFAX_ESCAPE;
1034 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,
Joe Perches475be4d2012-02-19 19:52:38 -08001035 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +02001036 deliver_status(ch, HW_MOD_FCERROR);
1037 break;
1038 default:
1039 break;
1040 }
1041}
1042
1043void
1044mISDNisar_irq(struct isar_hw *isar)
1045{
1046 struct isar_ch *ch;
1047
1048 get_irq_infos(isar);
1049 switch (isar->iis & ISAR_IIS_MSCMSD) {
1050 case ISAR_IIS_RDATA:
1051 ch = sel_bch_isar(isar, isar->iis >> 6);
1052 if (ch)
1053 isar_rcv_frame(ch);
1054 else {
1055 pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001056 isar->name, isar->iis, isar->cmsb,
1057 isar->clsb);
Karsten Keilda2272c92009-07-22 20:01:59 +02001058 isar->write_reg(isar->hw, ISAR_IIA, 0);
1059 }
1060 break;
1061 case ISAR_IIS_GSTEV:
1062 isar->write_reg(isar->hw, ISAR_IIA, 0);
1063 isar->bstat |= isar->cmsb;
1064 check_send(isar, isar->cmsb);
1065 break;
1066 case ISAR_IIS_BSTEV:
1067#ifdef ERROR_STATISTIC
1068 ch = sel_bch_isar(isar, isar->iis >> 6);
1069 if (ch) {
1070 if (isar->cmsb == BSTEV_TBO)
1071 ch->bch.err_tx++;
1072 if (isar->cmsb == BSTEV_RBO)
1073 ch->bch.err_rdo++;
1074 }
1075#endif
1076 pr_debug("%s: Buffer STEV dpath%d msb(%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001077 isar->name, isar->iis >> 6, isar->cmsb);
Karsten Keilda2272c92009-07-22 20:01:59 +02001078 isar->write_reg(isar->hw, ISAR_IIA, 0);
1079 break;
1080 case ISAR_IIS_PSTEV:
1081 ch = sel_bch_isar(isar, isar->iis >> 6);
1082 if (ch) {
1083 rcv_mbox(isar, NULL);
1084 if (ch->bch.state == ISDN_P_B_MODEM_ASYNC)
1085 isar_pump_statev_modem(ch, isar->cmsb);
1086 else if (ch->bch.state == ISDN_P_B_T30_FAX)
1087 isar_pump_statev_fax(ch, isar->cmsb);
1088 else if (ch->bch.state == ISDN_P_B_RAW) {
1089 int tt;
1090 tt = isar->cmsb | 0x30;
1091 if (tt == 0x3e)
1092 tt = '*';
1093 else if (tt == 0x3f)
1094 tt = '#';
1095 else if (tt > '9')
1096 tt += 7;
1097 tt |= DTMF_TONE_VAL;
1098 _queue_data(&ch->bch.ch, PH_CONTROL_IND,
Joe Perches475be4d2012-02-19 19:52:38 -08001099 MISDN_ID_ANY, sizeof(tt), &tt,
1100 GFP_ATOMIC);
Karsten Keilda2272c92009-07-22 20:01:59 +02001101 } else
1102 pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001103 isar->name, ch->bch.state,
1104 isar->cmsb);
Karsten Keilda2272c92009-07-22 20:01:59 +02001105 } else {
1106 pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001107 isar->name, isar->iis, isar->cmsb,
1108 isar->clsb);
Karsten Keilda2272c92009-07-22 20:01:59 +02001109 isar->write_reg(isar->hw, ISAR_IIA, 0);
1110 }
1111 break;
1112 case ISAR_IIS_PSTRSP:
1113 ch = sel_bch_isar(isar, isar->iis >> 6);
1114 if (ch) {
1115 rcv_mbox(isar, NULL);
1116 isar_pump_status_rsp(ch);
1117 } else {
1118 pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001119 isar->name, isar->iis, isar->cmsb,
1120 isar->clsb);
Karsten Keilda2272c92009-07-22 20:01:59 +02001121 isar->write_reg(isar->hw, ISAR_IIA, 0);
1122 }
1123 break;
1124 case ISAR_IIS_DIAG:
1125 case ISAR_IIS_BSTRSP:
1126 case ISAR_IIS_IOM2RSP:
1127 rcv_mbox(isar, NULL);
1128 break;
1129 case ISAR_IIS_INVMSG:
1130 rcv_mbox(isar, NULL);
1131 pr_debug("%s: invalid msg his:%x\n", isar->name, isar->cmsb);
1132 break;
1133 default:
1134 rcv_mbox(isar, NULL);
1135 pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001136 isar->name, isar->iis, isar->cmsb, isar->clsb);
Karsten Keilda2272c92009-07-22 20:01:59 +02001137 break;
1138 }
1139}
1140EXPORT_SYMBOL(mISDNisar_irq);
1141
1142static void
1143ftimer_handler(unsigned long data)
1144{
1145 struct isar_ch *ch = (struct isar_ch *)data;
1146
1147 pr_debug("%s: ftimer flags %lx\n", ch->is->name, ch->bch.Flags);
1148 test_and_clear_bit(FLG_FTI_RUN, &ch->bch.Flags);
1149 if (test_and_clear_bit(FLG_LL_CONN, &ch->bch.Flags))
1150 deliver_status(ch, HW_MOD_CONNECT);
1151}
1152
1153static void
1154setup_pump(struct isar_ch *ch) {
1155 u8 dps = SET_DPS(ch->dpath);
1156 u8 ctrl, param[6];
1157
1158 switch (ch->bch.state) {
1159 case ISDN_P_NONE:
1160 case ISDN_P_B_RAW:
1161 case ISDN_P_B_HDLC:
1162 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, PMOD_BYPASS, 0, NULL);
1163 break;
1164 case ISDN_P_B_L2DTMF:
1165 if (test_bit(FLG_DTMFSEND, &ch->bch.Flags)) {
1166 param[0] = 5; /* TOA 5 db */
1167 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,
Joe Perches475be4d2012-02-19 19:52:38 -08001168 PMOD_DTMF_TRANS, 1, param);
Karsten Keilda2272c92009-07-22 20:01:59 +02001169 } else {
1170 param[0] = 40; /* REL -46 dbm */
1171 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,
Joe Perches475be4d2012-02-19 19:52:38 -08001172 PMOD_DTMF, 1, param);
Karsten Keilda2272c92009-07-22 20:01:59 +02001173 }
1174 case ISDN_P_B_MODEM_ASYNC:
1175 ctrl = PMOD_DATAMODEM;
1176 if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {
1177 ctrl |= PCTRL_ORIG;
1178 param[5] = PV32P6_CTN;
1179 } else {
1180 param[5] = PV32P6_ATN;
1181 }
1182 param[0] = 6; /* 6 db */
1183 param[1] = PV32P2_V23R | PV32P2_V22A | PV32P2_V22B |
1184 PV32P2_V22C | PV32P2_V21 | PV32P2_BEL;
1185 param[2] = PV32P3_AMOD | PV32P3_V32B | PV32P3_V23B;
1186 param[3] = PV32P4_UT144;
1187 param[4] = PV32P5_UT144;
1188 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 6, param);
1189 break;
1190 case ISDN_P_B_T30_FAX:
1191 ctrl = PMOD_FAX;
1192 if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {
1193 ctrl |= PCTRL_ORIG;
1194 param[1] = PFAXP2_CTN;
1195 } else {
1196 param[1] = PFAXP2_ATN;
1197 }
1198 param[0] = 6; /* 6 db */
1199 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 2, param);
1200 ch->state = STFAX_NULL;
1201 ch->newcmd = 0;
1202 ch->newmod = 0;
1203 test_and_set_bit(FLG_FTI_RUN, &ch->bch.Flags);
1204 break;
1205 }
1206 udelay(1000);
1207 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
1208 udelay(1000);
1209}
1210
1211static void
1212setup_sart(struct isar_ch *ch) {
1213 u8 dps = SET_DPS(ch->dpath);
1214 u8 ctrl, param[2] = {0, 0};
1215
1216 switch (ch->bch.state) {
1217 case ISDN_P_NONE:
1218 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_DISABLE,
Joe Perches475be4d2012-02-19 19:52:38 -08001219 0, NULL);
Karsten Keilda2272c92009-07-22 20:01:59 +02001220 break;
1221 case ISDN_P_B_RAW:
1222 case ISDN_P_B_L2DTMF:
1223 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_BINARY,
Joe Perches475be4d2012-02-19 19:52:38 -08001224 2, param);
Karsten Keilda2272c92009-07-22 20:01:59 +02001225 break;
1226 case ISDN_P_B_HDLC:
1227 case ISDN_P_B_T30_FAX:
1228 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_HDLC,
Joe Perches475be4d2012-02-19 19:52:38 -08001229 1, param);
Karsten Keilda2272c92009-07-22 20:01:59 +02001230 break;
1231 case ISDN_P_B_MODEM_ASYNC:
1232 ctrl = SMODE_V14 | SCTRL_HDMC_BOTH;
1233 param[0] = S_P1_CHS_8;
1234 param[1] = S_P2_BFT_DEF;
1235 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, ctrl, 2, param);
1236 break;
1237 }
1238 udelay(1000);
1239 send_mbox(ch->is, dps | ISAR_HIS_BSTREQ, 0, 0, NULL);
1240 udelay(1000);
1241}
1242
1243static void
1244setup_iom2(struct isar_ch *ch) {
1245 u8 dps = SET_DPS(ch->dpath);
1246 u8 cmsb = IOM_CTRL_ENA, msg[5] = {IOM_P1_TXD, 0, 0, 0, 0};
1247
1248 if (ch->bch.nr == 2) {
1249 msg[1] = 1;
1250 msg[3] = 1;
1251 }
1252 switch (ch->bch.state) {
1253 case ISDN_P_NONE:
1254 cmsb = 0;
1255 /* dummy slot */
1256 msg[1] = ch->dpath + 2;
1257 msg[3] = ch->dpath + 2;
1258 break;
1259 case ISDN_P_B_RAW:
1260 case ISDN_P_B_HDLC:
1261 break;
1262 case ISDN_P_B_MODEM_ASYNC:
1263 case ISDN_P_B_T30_FAX:
1264 cmsb |= IOM_CTRL_RCV;
1265 case ISDN_P_B_L2DTMF:
1266 if (test_bit(FLG_DTMFSEND, &ch->bch.Flags))
1267 cmsb |= IOM_CTRL_RCV;
1268 cmsb |= IOM_CTRL_ALAW;
1269 break;
1270 }
1271 send_mbox(ch->is, dps | ISAR_HIS_IOM2CFG, cmsb, 5, msg);
1272 udelay(1000);
1273 send_mbox(ch->is, dps | ISAR_HIS_IOM2REQ, 0, 0, NULL);
1274 udelay(1000);
1275}
1276
1277static int
1278modeisar(struct isar_ch *ch, u32 bprotocol)
1279{
1280 /* Here we are selecting the best datapath for requested protocol */
1281 if (ch->bch.state == ISDN_P_NONE) { /* New Setup */
1282 switch (bprotocol) {
1283 case ISDN_P_NONE: /* init */
1284 if (!ch->dpath)
1285 /* no init for dpath 0 */
1286 return 0;
1287 test_and_clear_bit(FLG_HDLC, &ch->bch.Flags);
1288 test_and_clear_bit(FLG_TRANSPARENT, &ch->bch.Flags);
1289 break;
1290 case ISDN_P_B_RAW:
1291 case ISDN_P_B_HDLC:
1292 /* best is datapath 2 */
1293 if (!test_and_set_bit(ISAR_DP2_USE, &ch->is->Flags))
1294 ch->dpath = 2;
1295 else if (!test_and_set_bit(ISAR_DP1_USE,
Joe Perches475be4d2012-02-19 19:52:38 -08001296 &ch->is->Flags))
Karsten Keilda2272c92009-07-22 20:01:59 +02001297 ch->dpath = 1;
1298 else {
1299 pr_info("modeisar both pathes in use\n");
1300 return -EBUSY;
1301 }
1302 if (bprotocol == ISDN_P_B_HDLC)
1303 test_and_set_bit(FLG_HDLC, &ch->bch.Flags);
1304 else
1305 test_and_set_bit(FLG_TRANSPARENT,
Joe Perches475be4d2012-02-19 19:52:38 -08001306 &ch->bch.Flags);
Karsten Keilda2272c92009-07-22 20:01:59 +02001307 break;
1308 case ISDN_P_B_MODEM_ASYNC:
1309 case ISDN_P_B_T30_FAX:
1310 case ISDN_P_B_L2DTMF:
1311 /* only datapath 1 */
1312 if (!test_and_set_bit(ISAR_DP1_USE, &ch->is->Flags))
1313 ch->dpath = 1;
1314 else {
1315 pr_info("%s: ISAR modeisar analog functions"
1316 "only with DP1\n", ch->is->name);
1317 return -EBUSY;
1318 }
1319 break;
1320 default:
1321 pr_info("%s: protocol not known %x\n", ch->is->name,
1322 bprotocol);
1323 return -ENOPROTOOPT;
1324 }
1325 }
1326 pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch->is->name,
Joe Perches475be4d2012-02-19 19:52:38 -08001327 ch->bch.nr, ch->dpath, ch->bch.state, bprotocol);
Karsten Keilda2272c92009-07-22 20:01:59 +02001328 ch->bch.state = bprotocol;
1329 setup_pump(ch);
1330 setup_iom2(ch);
1331 setup_sart(ch);
1332 if (ch->bch.state == ISDN_P_NONE) {
1333 /* Clear resources */
1334 if (ch->dpath == 1)
1335 test_and_clear_bit(ISAR_DP1_USE, &ch->is->Flags);
1336 else if (ch->dpath == 2)
1337 test_and_clear_bit(ISAR_DP2_USE, &ch->is->Flags);
1338 ch->dpath = 0;
1339 ch->is->ctrl(ch->is->hw, HW_DEACT_IND, ch->bch.nr);
1340 } else
1341 ch->is->ctrl(ch->is->hw, HW_ACTIVATE_IND, ch->bch.nr);
1342 return 0;
1343}
1344
1345static void
1346isar_pump_cmd(struct isar_ch *ch, u32 cmd, u8 para)
1347{
1348 u8 dps = SET_DPS(ch->dpath);
1349 u8 ctrl = 0, nom = 0, p1 = 0;
1350
1351 pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001352 ch->is->name, cmd, para, ch->bch.state);
Karsten Keilda2272c92009-07-22 20:01:59 +02001353 switch (cmd) {
1354 case HW_MOD_FTM:
1355 if (ch->state == STFAX_READY) {
1356 p1 = para;
1357 ctrl = PCTRL_CMD_FTM;
1358 nom = 1;
1359 ch->state = STFAX_LINE;
1360 ch->cmd = ctrl;
1361 ch->mod = para;
1362 ch->newmod = 0;
1363 ch->newcmd = 0;
1364 ch->try_mod = 3;
1365 } else if ((ch->state == STFAX_ACTIV) &&
Joe Perches475be4d2012-02-19 19:52:38 -08001366 (ch->cmd == PCTRL_CMD_FTM) && (ch->mod == para))
Karsten Keilda2272c92009-07-22 20:01:59 +02001367 deliver_status(ch, HW_MOD_CONNECT);
1368 else {
1369 ch->newmod = para;
1370 ch->newcmd = PCTRL_CMD_FTM;
1371 nom = 0;
1372 ctrl = PCTRL_CMD_ESC;
1373 ch->state = STFAX_ESCAPE;
1374 }
1375 break;
1376 case HW_MOD_FTH:
1377 if (ch->state == STFAX_READY) {
1378 p1 = para;
1379 ctrl = PCTRL_CMD_FTH;
1380 nom = 1;
1381 ch->state = STFAX_LINE;
1382 ch->cmd = ctrl;
1383 ch->mod = para;
1384 ch->newmod = 0;
1385 ch->newcmd = 0;
1386 ch->try_mod = 3;
1387 } else if ((ch->state == STFAX_ACTIV) &&
Joe Perches475be4d2012-02-19 19:52:38 -08001388 (ch->cmd == PCTRL_CMD_FTH) && (ch->mod == para))
1389 deliver_status(ch, HW_MOD_CONNECT);
Karsten Keilda2272c92009-07-22 20:01:59 +02001390 else {
1391 ch->newmod = para;
1392 ch->newcmd = PCTRL_CMD_FTH;
1393 nom = 0;
1394 ctrl = PCTRL_CMD_ESC;
1395 ch->state = STFAX_ESCAPE;
1396 }
1397 break;
1398 case HW_MOD_FRM:
1399 if (ch->state == STFAX_READY) {
1400 p1 = para;
1401 ctrl = PCTRL_CMD_FRM;
1402 nom = 1;
1403 ch->state = STFAX_LINE;
1404 ch->cmd = ctrl;
1405 ch->mod = para;
1406 ch->newmod = 0;
1407 ch->newcmd = 0;
1408 ch->try_mod = 3;
1409 } else if ((ch->state == STFAX_ACTIV) &&
Joe Perches475be4d2012-02-19 19:52:38 -08001410 (ch->cmd == PCTRL_CMD_FRM) && (ch->mod == para))
Karsten Keilda2272c92009-07-22 20:01:59 +02001411 deliver_status(ch, HW_MOD_CONNECT);
1412 else {
1413 ch->newmod = para;
1414 ch->newcmd = PCTRL_CMD_FRM;
1415 nom = 0;
1416 ctrl = PCTRL_CMD_ESC;
1417 ch->state = STFAX_ESCAPE;
1418 }
1419 break;
1420 case HW_MOD_FRH:
1421 if (ch->state == STFAX_READY) {
1422 p1 = para;
1423 ctrl = PCTRL_CMD_FRH;
1424 nom = 1;
1425 ch->state = STFAX_LINE;
1426 ch->cmd = ctrl;
1427 ch->mod = para;
1428 ch->newmod = 0;
1429 ch->newcmd = 0;
1430 ch->try_mod = 3;
1431 } else if ((ch->state == STFAX_ACTIV) &&
Joe Perches475be4d2012-02-19 19:52:38 -08001432 (ch->cmd == PCTRL_CMD_FRH) && (ch->mod == para))
Karsten Keilda2272c92009-07-22 20:01:59 +02001433 deliver_status(ch, HW_MOD_CONNECT);
1434 else {
1435 ch->newmod = para;
1436 ch->newcmd = PCTRL_CMD_FRH;
1437 nom = 0;
1438 ctrl = PCTRL_CMD_ESC;
1439 ch->state = STFAX_ESCAPE;
1440 }
1441 break;
1442 case PCTRL_CMD_TDTMF:
1443 p1 = para;
1444 nom = 1;
1445 ctrl = PCTRL_CMD_TDTMF;
1446 break;
1447 }
1448 if (ctrl)
1449 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, ctrl, nom, &p1);
1450}
1451
1452static void
1453isar_setup(struct isar_hw *isar)
1454{
1455 u8 msg;
1456 int i;
1457
1458 /* Dpath 1, 2 */
1459 msg = 61;
1460 for (i = 0; i < 2; i++) {
1461 /* Buffer Config */
1462 send_mbox(isar, (i ? ISAR_HIS_DPS2 : ISAR_HIS_DPS1) |
Joe Perches475be4d2012-02-19 19:52:38 -08001463 ISAR_HIS_P12CFG, 4, 1, &msg);
Karsten Keilda2272c92009-07-22 20:01:59 +02001464 isar->ch[i].mml = msg;
1465 isar->ch[i].bch.state = 0;
1466 isar->ch[i].dpath = i + 1;
1467 modeisar(&isar->ch[i], ISDN_P_NONE);
1468 }
1469}
1470
1471static int
1472isar_l2l1(struct mISDNchannel *ch, struct sk_buff *skb)
1473{
1474 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1475 struct isar_ch *ich = container_of(bch, struct isar_ch, bch);
1476 int ret = -EINVAL;
1477 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1478 u32 id, *val;
1479 u_long flags;
1480
1481 switch (hh->prim) {
1482 case PH_DATA_REQ:
1483 spin_lock_irqsave(ich->is->hwlock, flags);
1484 ret = bchannel_senddata(bch, skb);
1485 if (ret > 0) { /* direct TX */
Karsten Keilda2272c92009-07-22 20:01:59 +02001486 ret = 0;
1487 isar_fill_fifo(ich);
Karsten Keil8bfddfb2012-05-15 23:51:02 +00001488 }
1489 spin_unlock_irqrestore(ich->is->hwlock, flags);
Karsten Keilda2272c92009-07-22 20:01:59 +02001490 return ret;
1491 case PH_ACTIVATE_REQ:
1492 spin_lock_irqsave(ich->is->hwlock, flags);
1493 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags))
1494 ret = modeisar(ich, ch->protocol);
1495 else
1496 ret = 0;
1497 spin_unlock_irqrestore(ich->is->hwlock, flags);
1498 if (!ret)
1499 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
Joe Perches475be4d2012-02-19 19:52:38 -08001500 NULL, GFP_KERNEL);
Karsten Keilda2272c92009-07-22 20:01:59 +02001501 break;
1502 case PH_DEACTIVATE_REQ:
1503 spin_lock_irqsave(ich->is->hwlock, flags);
1504 mISDN_clear_bchannel(bch);
1505 modeisar(ich, ISDN_P_NONE);
1506 spin_unlock_irqrestore(ich->is->hwlock, flags);
1507 _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
Joe Perches475be4d2012-02-19 19:52:38 -08001508 NULL, GFP_KERNEL);
Karsten Keilda2272c92009-07-22 20:01:59 +02001509 ret = 0;
1510 break;
1511 case PH_CONTROL_REQ:
1512 val = (u32 *)skb->data;
1513 pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich->is->name,
Joe Perches475be4d2012-02-19 19:52:38 -08001514 hh->id, *val);
Karsten Keilda2272c92009-07-22 20:01:59 +02001515 if ((hh->id == 0) && ((*val & ~DTMF_TONE_MASK) ==
Joe Perches475be4d2012-02-19 19:52:38 -08001516 DTMF_TONE_VAL)) {
Karsten Keilda2272c92009-07-22 20:01:59 +02001517 if (bch->state == ISDN_P_B_L2DTMF) {
1518 char tt = *val & DTMF_TONE_MASK;
1519
1520 if (tt == '*')
1521 tt = 0x1e;
1522 else if (tt == '#')
1523 tt = 0x1f;
1524 else if (tt > '9')
1525 tt -= 7;
1526 tt &= 0x1f;
1527 spin_lock_irqsave(ich->is->hwlock, flags);
1528 isar_pump_cmd(ich, PCTRL_CMD_TDTMF, tt);
1529 spin_unlock_irqrestore(ich->is->hwlock, flags);
1530 } else {
1531 pr_info("%s: DTMF send wrong protocol %x\n",
1532 __func__, bch->state);
1533 return -EINVAL;
1534 }
1535 } else if ((hh->id == HW_MOD_FRM) || (hh->id == HW_MOD_FRH) ||
Joe Perches475be4d2012-02-19 19:52:38 -08001536 (hh->id == HW_MOD_FTM) || (hh->id == HW_MOD_FTH)) {
Karsten Keilda2272c92009-07-22 20:01:59 +02001537 for (id = 0; id < FAXMODCNT; id++)
1538 if (faxmodulation[id] == *val)
1539 break;
1540 if ((FAXMODCNT > id) &&
1541 test_bit(FLG_INITIALIZED, &bch->Flags)) {
1542 pr_debug("%s: isar: new mod\n", ich->is->name);
1543 isar_pump_cmd(ich, hh->id, *val);
1544 ret = 0;
1545 } else {
1546 pr_info("%s: wrong modulation\n",
1547 ich->is->name);
1548 ret = -EINVAL;
1549 }
1550 } else if (hh->id == HW_MOD_LASTDATA)
1551 test_and_set_bit(FLG_DLEETX, &bch->Flags);
1552 else {
1553 pr_info("%s: unknown PH_CONTROL_REQ %x\n",
1554 ich->is->name, hh->id);
1555 ret = -EINVAL;
1556 }
1557 default:
1558 pr_info("%s: %s unknown prim(%x,%x)\n",
1559 ich->is->name, __func__, hh->prim, hh->id);
1560 ret = -EINVAL;
1561 }
1562 if (!ret)
1563 dev_kfree_skb(skb);
1564 return ret;
1565}
1566
1567static int
1568channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
1569{
1570 int ret = 0;
1571
1572 switch (cq->op) {
1573 case MISDN_CTRL_GETOP:
1574 cq->op = 0;
1575 break;
Joe Perches475be4d2012-02-19 19:52:38 -08001576 /* Nothing implemented yet */
Karsten Keilda2272c92009-07-22 20:01:59 +02001577 case MISDN_CTRL_FILL_EMPTY:
1578 default:
1579 pr_info("%s: unknown Op %x\n", __func__, cq->op);
1580 ret = -EINVAL;
1581 break;
1582 }
1583 return ret;
1584}
1585
1586static int
1587isar_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
1588{
1589 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1590 struct isar_ch *ich = container_of(bch, struct isar_ch, bch);
1591 int ret = -EINVAL;
1592 u_long flags;
1593
1594 pr_debug("%s: %s cmd:%x %p\n", ich->is->name, __func__, cmd, arg);
1595 switch (cmd) {
1596 case CLOSE_CHANNEL:
1597 test_and_clear_bit(FLG_OPEN, &bch->Flags);
Karsten Keil13681122012-05-15 23:51:01 +00001598 spin_lock_irqsave(ich->is->hwlock, flags);
1599 mISDN_freebchannel(bch);
1600 modeisar(ich, ISDN_P_NONE);
1601 spin_unlock_irqrestore(ich->is->hwlock, flags);
Karsten Keilda2272c92009-07-22 20:01:59 +02001602 ch->protocol = ISDN_P_NONE;
1603 ch->peer = NULL;
1604 module_put(ich->is->owner);
1605 ret = 0;
1606 break;
1607 case CONTROL_CHANNEL:
1608 ret = channel_bctrl(bch, arg);
1609 break;
1610 default:
1611 pr_info("%s: %s unknown prim(%x)\n",
1612 ich->is->name, __func__, cmd);
1613 }
1614 return ret;
1615}
1616
1617static void
1618free_isar(struct isar_hw *isar)
1619{
1620 modeisar(&isar->ch[0], ISDN_P_NONE);
1621 modeisar(&isar->ch[1], ISDN_P_NONE);
1622 del_timer(&isar->ch[0].ftimer);
1623 del_timer(&isar->ch[1].ftimer);
1624 test_and_clear_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);
1625 test_and_clear_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);
1626}
1627
1628static int
1629init_isar(struct isar_hw *isar)
1630{
1631 int cnt = 3;
1632
1633 while (cnt--) {
1634 isar->version = ISARVersion(isar);
1635 if (isar->ch[0].bch.debug & DEBUG_HW)
1636 pr_notice("%s: Testing version %d (%d time)\n",
Joe Perches475be4d2012-02-19 19:52:38 -08001637 isar->name, isar->version, 3 - cnt);
Karsten Keilda2272c92009-07-22 20:01:59 +02001638 if (isar->version == 1)
1639 break;
1640 isar->ctrl(isar->hw, HW_RESET_REQ, 0);
1641 }
1642 if (isar->version != 1)
1643 return -EINVAL;
1644 isar->ch[0].ftimer.function = &ftimer_handler;
1645 isar->ch[0].ftimer.data = (long)&isar->ch[0];
1646 init_timer(&isar->ch[0].ftimer);
1647 test_and_set_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);
1648 isar->ch[1].ftimer.function = &ftimer_handler;
1649 isar->ch[1].ftimer.data = (long)&isar->ch[1];
1650 init_timer(&isar->ch[1].ftimer);
1651 test_and_set_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);
1652 return 0;
1653}
1654
1655static int
1656isar_open(struct isar_hw *isar, struct channel_req *rq)
1657{
1658 struct bchannel *bch;
1659
Dan Carpenter819a1002012-03-26 21:20:48 +00001660 if (rq->adr.channel == 0 || rq->adr.channel > 2)
Karsten Keilda2272c92009-07-22 20:01:59 +02001661 return -EINVAL;
1662 if (rq->protocol == ISDN_P_NONE)
1663 return -EINVAL;
1664 bch = &isar->ch[rq->adr.channel - 1].bch;
1665 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
1666 return -EBUSY; /* b-channel can be only open once */
1667 test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags);
1668 bch->ch.protocol = rq->protocol;
1669 rq->ch = &bch->ch;
1670 return 0;
1671}
1672
1673u32
1674mISDNisar_init(struct isar_hw *isar, void *hw)
1675{
1676 u32 ret, i;
1677
1678 isar->hw = hw;
1679 for (i = 0; i < 2; i++) {
1680 isar->ch[i].bch.nr = i + 1;
1681 mISDN_initbchannel(&isar->ch[i].bch, MAX_DATA_MEM);
1682 isar->ch[i].bch.ch.nr = i + 1;
1683 isar->ch[i].bch.ch.send = &isar_l2l1;
1684 isar->ch[i].bch.ch.ctrl = isar_bctrl;
1685 isar->ch[i].bch.hw = hw;
1686 isar->ch[i].is = isar;
1687 }
1688
1689 isar->init = &init_isar;
1690 isar->release = &free_isar;
1691 isar->firmware = &load_firmware;
1692 isar->open = &isar_open;
1693
1694 ret = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
1695 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK)) |
1696 (1 << (ISDN_P_B_L2DTMF & ISDN_P_B_MASK)) |
1697 (1 << (ISDN_P_B_MODEM_ASYNC & ISDN_P_B_MASK)) |
1698 (1 << (ISDN_P_B_T30_FAX & ISDN_P_B_MASK));
1699
1700 return ret;
1701}
1702EXPORT_SYMBOL(mISDNisar_init);
1703
Peter Huewe88850742009-12-22 09:27:06 +01001704static int __init isar_mod_init(void)
Karsten Keilda2272c92009-07-22 20:01:59 +02001705{
1706 pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV);
1707 return 0;
1708}
1709
Peter Huewe88850742009-12-22 09:27:06 +01001710static void __exit isar_mod_cleanup(void)
Karsten Keilda2272c92009-07-22 20:01:59 +02001711{
1712 pr_notice("mISDN: ISAR module unloaded\n");
1713}
1714module_init(isar_mod_init);
1715module_exit(isar_mod_cleanup);