mISDNisar.c 43 KB

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