mISDNisar.c 43 KB

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