isac.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /* $Id: isac.c,v 1.31.2.3 2004/01/13 14:31:25 keil Exp $
  2. *
  3. * ISAC specific routines
  4. *
  5. * Author Karsten Keil
  6. * Copyright by Karsten Keil <keil@isdn4linux.de>
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. * For changes and modifications please read
  12. * Documentation/isdn/HiSax.cert
  13. *
  14. */
  15. #include "hisax.h"
  16. #include "isac.h"
  17. #include "arcofi.h"
  18. #include "isdnl1.h"
  19. #include <linux/interrupt.h>
  20. #include <linux/slab.h>
  21. #include <linux/init.h>
  22. #define DBUSY_TIMER_VALUE 80
  23. #define ARCOFI_USE 1
  24. static char *ISACVer[] =
  25. {"2086/2186 V1.1", "2085 B1", "2085 B2",
  26. "2085 V2.3"};
  27. void ISACVersion(struct IsdnCardState *cs, char *s)
  28. {
  29. int val;
  30. val = cs->readisac(cs, ISAC_RBCH);
  31. printk(KERN_INFO "%s ISAC version (%x): %s\n", s, val, ISACVer[(val >> 5) & 3]);
  32. }
  33. static void
  34. ph_command(struct IsdnCardState *cs, unsigned int command)
  35. {
  36. if (cs->debug & L1_DEB_ISAC)
  37. debugl1(cs, "ph_command %x", command);
  38. cs->writeisac(cs, ISAC_CIX0, (command << 2) | 3);
  39. }
  40. static void
  41. isac_new_ph(struct IsdnCardState *cs)
  42. {
  43. switch (cs->dc.isac.ph_state) {
  44. case (ISAC_IND_RS):
  45. case (ISAC_IND_EI):
  46. ph_command(cs, ISAC_CMD_DUI);
  47. l1_msg(cs, HW_RESET | INDICATION, NULL);
  48. break;
  49. case (ISAC_IND_DID):
  50. l1_msg(cs, HW_DEACTIVATE | CONFIRM, NULL);
  51. break;
  52. case (ISAC_IND_DR):
  53. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  54. break;
  55. case (ISAC_IND_PU):
  56. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  57. break;
  58. case (ISAC_IND_RSY):
  59. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  60. break;
  61. case (ISAC_IND_ARD):
  62. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  63. break;
  64. case (ISAC_IND_AI8):
  65. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  66. break;
  67. case (ISAC_IND_AI10):
  68. l1_msg(cs, HW_INFO4_P10 | INDICATION, NULL);
  69. break;
  70. default:
  71. break;
  72. }
  73. }
  74. static void
  75. isac_bh(struct work_struct *work)
  76. {
  77. struct IsdnCardState *cs =
  78. container_of(work, struct IsdnCardState, tqueue);
  79. struct PStack *stptr;
  80. if (test_and_clear_bit(D_CLEARBUSY, &cs->event)) {
  81. if (cs->debug)
  82. debugl1(cs, "D-Channel Busy cleared");
  83. stptr = cs->stlist;
  84. while (stptr != NULL) {
  85. stptr->l1.l1l2(stptr, PH_PAUSE | CONFIRM, NULL);
  86. stptr = stptr->next;
  87. }
  88. }
  89. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event))
  90. isac_new_ph(cs);
  91. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  92. DChannel_proc_rcv(cs);
  93. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  94. DChannel_proc_xmt(cs);
  95. #if ARCOFI_USE
  96. if (!test_bit(HW_ARCOFI, &cs->HW_Flags))
  97. return;
  98. if (test_and_clear_bit(D_RX_MON1, &cs->event))
  99. arcofi_fsm(cs, ARCOFI_RX_END, NULL);
  100. if (test_and_clear_bit(D_TX_MON1, &cs->event))
  101. arcofi_fsm(cs, ARCOFI_TX_END, NULL);
  102. #endif
  103. }
  104. static void
  105. isac_empty_fifo(struct IsdnCardState *cs, int count)
  106. {
  107. u_char *ptr;
  108. if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
  109. debugl1(cs, "isac_empty_fifo");
  110. if ((cs->rcvidx + count) >= MAX_DFRAME_LEN_L1) {
  111. if (cs->debug & L1_DEB_WARN)
  112. debugl1(cs, "isac_empty_fifo overrun %d",
  113. cs->rcvidx + count);
  114. cs->writeisac(cs, ISAC_CMDR, 0x80);
  115. cs->rcvidx = 0;
  116. return;
  117. }
  118. ptr = cs->rcvbuf + cs->rcvidx;
  119. cs->rcvidx += count;
  120. cs->readisacfifo(cs, ptr, count);
  121. cs->writeisac(cs, ISAC_CMDR, 0x80);
  122. if (cs->debug & L1_DEB_ISAC_FIFO) {
  123. char *t = cs->dlog;
  124. t += sprintf(t, "isac_empty_fifo cnt %d", count);
  125. QuickHex(t, ptr, count);
  126. debugl1(cs, "%s", cs->dlog);
  127. }
  128. }
  129. static void
  130. isac_fill_fifo(struct IsdnCardState *cs)
  131. {
  132. int count, more;
  133. u_char *ptr;
  134. if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
  135. debugl1(cs, "isac_fill_fifo");
  136. if (!cs->tx_skb)
  137. return;
  138. count = cs->tx_skb->len;
  139. if (count <= 0)
  140. return;
  141. more = 0;
  142. if (count > 32) {
  143. more = !0;
  144. count = 32;
  145. }
  146. ptr = cs->tx_skb->data;
  147. skb_pull(cs->tx_skb, count);
  148. cs->tx_cnt += count;
  149. cs->writeisacfifo(cs, ptr, count);
  150. cs->writeisac(cs, ISAC_CMDR, more ? 0x8 : 0xa);
  151. if (test_and_set_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
  152. debugl1(cs, "isac_fill_fifo dbusytimer running");
  153. del_timer(&cs->dbusytimer);
  154. }
  155. init_timer(&cs->dbusytimer);
  156. cs->dbusytimer.expires = jiffies + ((DBUSY_TIMER_VALUE * HZ)/1000);
  157. add_timer(&cs->dbusytimer);
  158. if (cs->debug & L1_DEB_ISAC_FIFO) {
  159. char *t = cs->dlog;
  160. t += sprintf(t, "isac_fill_fifo cnt %d", count);
  161. QuickHex(t, ptr, count);
  162. debugl1(cs, "%s", cs->dlog);
  163. }
  164. }
  165. void
  166. isac_interrupt(struct IsdnCardState *cs, u_char val)
  167. {
  168. u_char exval, v1;
  169. struct sk_buff *skb;
  170. unsigned int count;
  171. if (cs->debug & L1_DEB_ISAC)
  172. debugl1(cs, "ISAC interrupt %x", val);
  173. if (val & 0x80) { /* RME */
  174. exval = cs->readisac(cs, ISAC_RSTA);
  175. if ((exval & 0x70) != 0x20) {
  176. if (exval & 0x40) {
  177. if (cs->debug & L1_DEB_WARN)
  178. debugl1(cs, "ISAC RDO");
  179. #ifdef ERROR_STATISTIC
  180. cs->err_rx++;
  181. #endif
  182. }
  183. if (!(exval & 0x20)) {
  184. if (cs->debug & L1_DEB_WARN)
  185. debugl1(cs, "ISAC CRC error");
  186. #ifdef ERROR_STATISTIC
  187. cs->err_crc++;
  188. #endif
  189. }
  190. cs->writeisac(cs, ISAC_CMDR, 0x80);
  191. } else {
  192. count = cs->readisac(cs, ISAC_RBCL) & 0x1f;
  193. if (count == 0)
  194. count = 32;
  195. isac_empty_fifo(cs, count);
  196. if ((count = cs->rcvidx) > 0) {
  197. cs->rcvidx = 0;
  198. if (!(skb = alloc_skb(count, GFP_ATOMIC)))
  199. printk(KERN_WARNING "HiSax: D receive out of memory\n");
  200. else {
  201. memcpy(skb_put(skb, count), cs->rcvbuf, count);
  202. skb_queue_tail(&cs->rq, skb);
  203. }
  204. }
  205. }
  206. cs->rcvidx = 0;
  207. schedule_event(cs, D_RCVBUFREADY);
  208. }
  209. if (val & 0x40) { /* RPF */
  210. isac_empty_fifo(cs, 32);
  211. }
  212. if (val & 0x20) { /* RSC */
  213. /* never */
  214. if (cs->debug & L1_DEB_WARN)
  215. debugl1(cs, "ISAC RSC interrupt");
  216. }
  217. if (val & 0x10) { /* XPR */
  218. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  219. del_timer(&cs->dbusytimer);
  220. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  221. schedule_event(cs, D_CLEARBUSY);
  222. if (cs->tx_skb) {
  223. if (cs->tx_skb->len) {
  224. isac_fill_fifo(cs);
  225. goto afterXPR;
  226. } else {
  227. dev_kfree_skb_irq(cs->tx_skb);
  228. cs->tx_cnt = 0;
  229. cs->tx_skb = NULL;
  230. }
  231. }
  232. if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
  233. cs->tx_cnt = 0;
  234. isac_fill_fifo(cs);
  235. } else
  236. schedule_event(cs, D_XMTBUFREADY);
  237. }
  238. afterXPR:
  239. if (val & 0x04) { /* CISQ */
  240. exval = cs->readisac(cs, ISAC_CIR0);
  241. if (cs->debug & L1_DEB_ISAC)
  242. debugl1(cs, "ISAC CIR0 %02X", exval);
  243. if (exval & 2) {
  244. cs->dc.isac.ph_state = (exval >> 2) & 0xf;
  245. if (cs->debug & L1_DEB_ISAC)
  246. debugl1(cs, "ph_state change %x", cs->dc.isac.ph_state);
  247. schedule_event(cs, D_L1STATECHANGE);
  248. }
  249. if (exval & 1) {
  250. exval = cs->readisac(cs, ISAC_CIR1);
  251. if (cs->debug & L1_DEB_ISAC)
  252. debugl1(cs, "ISAC CIR1 %02X", exval);
  253. }
  254. }
  255. if (val & 0x02) { /* SIN */
  256. /* never */
  257. if (cs->debug & L1_DEB_WARN)
  258. debugl1(cs, "ISAC SIN interrupt");
  259. }
  260. if (val & 0x01) { /* EXI */
  261. exval = cs->readisac(cs, ISAC_EXIR);
  262. if (cs->debug & L1_DEB_WARN)
  263. debugl1(cs, "ISAC EXIR %02x", exval);
  264. if (exval & 0x80) { /* XMR */
  265. debugl1(cs, "ISAC XMR");
  266. printk(KERN_WARNING "HiSax: ISAC XMR\n");
  267. }
  268. if (exval & 0x40) { /* XDU */
  269. debugl1(cs, "ISAC XDU");
  270. printk(KERN_WARNING "HiSax: ISAC XDU\n");
  271. #ifdef ERROR_STATISTIC
  272. cs->err_tx++;
  273. #endif
  274. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  275. del_timer(&cs->dbusytimer);
  276. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  277. schedule_event(cs, D_CLEARBUSY);
  278. if (cs->tx_skb) { /* Restart frame */
  279. skb_push(cs->tx_skb, cs->tx_cnt);
  280. cs->tx_cnt = 0;
  281. isac_fill_fifo(cs);
  282. } else {
  283. printk(KERN_WARNING "HiSax: ISAC XDU no skb\n");
  284. debugl1(cs, "ISAC XDU no skb");
  285. }
  286. }
  287. if (exval & 0x04) { /* MOS */
  288. v1 = cs->readisac(cs, ISAC_MOSR);
  289. if (cs->debug & L1_DEB_MONITOR)
  290. debugl1(cs, "ISAC MOSR %02x", v1);
  291. #if ARCOFI_USE
  292. if (v1 & 0x08) {
  293. if (!cs->dc.isac.mon_rx) {
  294. if (!(cs->dc.isac.mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
  295. if (cs->debug & L1_DEB_WARN)
  296. debugl1(cs, "ISAC MON RX out of memory!");
  297. cs->dc.isac.mocr &= 0xf0;
  298. cs->dc.isac.mocr |= 0x0a;
  299. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  300. goto afterMONR0;
  301. } else
  302. cs->dc.isac.mon_rxp = 0;
  303. }
  304. if (cs->dc.isac.mon_rxp >= MAX_MON_FRAME) {
  305. cs->dc.isac.mocr &= 0xf0;
  306. cs->dc.isac.mocr |= 0x0a;
  307. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  308. cs->dc.isac.mon_rxp = 0;
  309. if (cs->debug & L1_DEB_WARN)
  310. debugl1(cs, "ISAC MON RX overflow!");
  311. goto afterMONR0;
  312. }
  313. cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp++] = cs->readisac(cs, ISAC_MOR0);
  314. if (cs->debug & L1_DEB_MONITOR)
  315. debugl1(cs, "ISAC MOR0 %02x", cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp - 1]);
  316. if (cs->dc.isac.mon_rxp == 1) {
  317. cs->dc.isac.mocr |= 0x04;
  318. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  319. }
  320. }
  321. afterMONR0:
  322. if (v1 & 0x80) {
  323. if (!cs->dc.isac.mon_rx) {
  324. if (!(cs->dc.isac.mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
  325. if (cs->debug & L1_DEB_WARN)
  326. debugl1(cs, "ISAC MON RX out of memory!");
  327. cs->dc.isac.mocr &= 0x0f;
  328. cs->dc.isac.mocr |= 0xa0;
  329. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  330. goto afterMONR1;
  331. } else
  332. cs->dc.isac.mon_rxp = 0;
  333. }
  334. if (cs->dc.isac.mon_rxp >= MAX_MON_FRAME) {
  335. cs->dc.isac.mocr &= 0x0f;
  336. cs->dc.isac.mocr |= 0xa0;
  337. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  338. cs->dc.isac.mon_rxp = 0;
  339. if (cs->debug & L1_DEB_WARN)
  340. debugl1(cs, "ISAC MON RX overflow!");
  341. goto afterMONR1;
  342. }
  343. cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp++] = cs->readisac(cs, ISAC_MOR1);
  344. if (cs->debug & L1_DEB_MONITOR)
  345. debugl1(cs, "ISAC MOR1 %02x", cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp - 1]);
  346. cs->dc.isac.mocr |= 0x40;
  347. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  348. }
  349. afterMONR1:
  350. if (v1 & 0x04) {
  351. cs->dc.isac.mocr &= 0xf0;
  352. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  353. cs->dc.isac.mocr |= 0x0a;
  354. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  355. schedule_event(cs, D_RX_MON0);
  356. }
  357. if (v1 & 0x40) {
  358. cs->dc.isac.mocr &= 0x0f;
  359. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  360. cs->dc.isac.mocr |= 0xa0;
  361. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  362. schedule_event(cs, D_RX_MON1);
  363. }
  364. if (v1 & 0x02) {
  365. if ((!cs->dc.isac.mon_tx) || (cs->dc.isac.mon_txc &&
  366. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc) &&
  367. !(v1 & 0x08))) {
  368. cs->dc.isac.mocr &= 0xf0;
  369. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  370. cs->dc.isac.mocr |= 0x0a;
  371. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  372. if (cs->dc.isac.mon_txc &&
  373. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc))
  374. schedule_event(cs, D_TX_MON0);
  375. goto AfterMOX0;
  376. }
  377. if (cs->dc.isac.mon_txc && (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc)) {
  378. schedule_event(cs, D_TX_MON0);
  379. goto AfterMOX0;
  380. }
  381. cs->writeisac(cs, ISAC_MOX0,
  382. cs->dc.isac.mon_tx[cs->dc.isac.mon_txp++]);
  383. if (cs->debug & L1_DEB_MONITOR)
  384. debugl1(cs, "ISAC %02x -> MOX0", cs->dc.isac.mon_tx[cs->dc.isac.mon_txp - 1]);
  385. }
  386. AfterMOX0:
  387. if (v1 & 0x20) {
  388. if ((!cs->dc.isac.mon_tx) || (cs->dc.isac.mon_txc &&
  389. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc) &&
  390. !(v1 & 0x80))) {
  391. cs->dc.isac.mocr &= 0x0f;
  392. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  393. cs->dc.isac.mocr |= 0xa0;
  394. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  395. if (cs->dc.isac.mon_txc &&
  396. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc))
  397. schedule_event(cs, D_TX_MON1);
  398. goto AfterMOX1;
  399. }
  400. if (cs->dc.isac.mon_txc && (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc)) {
  401. schedule_event(cs, D_TX_MON1);
  402. goto AfterMOX1;
  403. }
  404. cs->writeisac(cs, ISAC_MOX1,
  405. cs->dc.isac.mon_tx[cs->dc.isac.mon_txp++]);
  406. if (cs->debug & L1_DEB_MONITOR)
  407. debugl1(cs, "ISAC %02x -> MOX1", cs->dc.isac.mon_tx[cs->dc.isac.mon_txp - 1]);
  408. }
  409. AfterMOX1:;
  410. #endif
  411. }
  412. }
  413. }
  414. static void
  415. ISAC_l1hw(struct PStack *st, int pr, void *arg)
  416. {
  417. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  418. struct sk_buff *skb = arg;
  419. u_long flags;
  420. int val;
  421. switch (pr) {
  422. case (PH_DATA | REQUEST):
  423. if (cs->debug & DEB_DLOG_HEX)
  424. LogFrame(cs, skb->data, skb->len);
  425. if (cs->debug & DEB_DLOG_VERBOSE)
  426. dlogframe(cs, skb, 0);
  427. spin_lock_irqsave(&cs->lock, flags);
  428. if (cs->tx_skb) {
  429. skb_queue_tail(&cs->sq, skb);
  430. #ifdef L2FRAME_DEBUG /* psa */
  431. if (cs->debug & L1_DEB_LAPD)
  432. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  433. #endif
  434. } else {
  435. cs->tx_skb = skb;
  436. cs->tx_cnt = 0;
  437. #ifdef L2FRAME_DEBUG /* psa */
  438. if (cs->debug & L1_DEB_LAPD)
  439. Logl2Frame(cs, skb, "PH_DATA", 0);
  440. #endif
  441. isac_fill_fifo(cs);
  442. }
  443. spin_unlock_irqrestore(&cs->lock, flags);
  444. break;
  445. case (PH_PULL | INDICATION):
  446. spin_lock_irqsave(&cs->lock, flags);
  447. if (cs->tx_skb) {
  448. if (cs->debug & L1_DEB_WARN)
  449. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  450. skb_queue_tail(&cs->sq, skb);
  451. } else {
  452. if (cs->debug & DEB_DLOG_HEX)
  453. LogFrame(cs, skb->data, skb->len);
  454. if (cs->debug & DEB_DLOG_VERBOSE)
  455. dlogframe(cs, skb, 0);
  456. cs->tx_skb = skb;
  457. cs->tx_cnt = 0;
  458. #ifdef L2FRAME_DEBUG /* psa */
  459. if (cs->debug & L1_DEB_LAPD)
  460. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  461. #endif
  462. isac_fill_fifo(cs);
  463. }
  464. spin_unlock_irqrestore(&cs->lock, flags);
  465. break;
  466. case (PH_PULL | REQUEST):
  467. #ifdef L2FRAME_DEBUG /* psa */
  468. if (cs->debug & L1_DEB_LAPD)
  469. debugl1(cs, "-> PH_REQUEST_PULL");
  470. #endif
  471. if (!cs->tx_skb) {
  472. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  473. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  474. } else
  475. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  476. break;
  477. case (HW_RESET | REQUEST):
  478. spin_lock_irqsave(&cs->lock, flags);
  479. if ((cs->dc.isac.ph_state == ISAC_IND_EI) ||
  480. (cs->dc.isac.ph_state == ISAC_IND_DR) ||
  481. (cs->dc.isac.ph_state == ISAC_IND_RS))
  482. ph_command(cs, ISAC_CMD_TIM);
  483. else
  484. ph_command(cs, ISAC_CMD_RS);
  485. spin_unlock_irqrestore(&cs->lock, flags);
  486. break;
  487. case (HW_ENABLE | REQUEST):
  488. spin_lock_irqsave(&cs->lock, flags);
  489. ph_command(cs, ISAC_CMD_TIM);
  490. spin_unlock_irqrestore(&cs->lock, flags);
  491. break;
  492. case (HW_INFO3 | REQUEST):
  493. spin_lock_irqsave(&cs->lock, flags);
  494. ph_command(cs, ISAC_CMD_AR8);
  495. spin_unlock_irqrestore(&cs->lock, flags);
  496. break;
  497. case (HW_TESTLOOP | REQUEST):
  498. spin_lock_irqsave(&cs->lock, flags);
  499. val = 0;
  500. if (1 & (long) arg)
  501. val |= 0x0c;
  502. if (2 & (long) arg)
  503. val |= 0x3;
  504. if (test_bit(HW_IOM1, &cs->HW_Flags)) {
  505. /* IOM 1 Mode */
  506. if (!val) {
  507. cs->writeisac(cs, ISAC_SPCR, 0xa);
  508. cs->writeisac(cs, ISAC_ADF1, 0x2);
  509. } else {
  510. cs->writeisac(cs, ISAC_SPCR, val);
  511. cs->writeisac(cs, ISAC_ADF1, 0xa);
  512. }
  513. } else {
  514. /* IOM 2 Mode */
  515. cs->writeisac(cs, ISAC_SPCR, val);
  516. if (val)
  517. cs->writeisac(cs, ISAC_ADF1, 0x8);
  518. else
  519. cs->writeisac(cs, ISAC_ADF1, 0x0);
  520. }
  521. spin_unlock_irqrestore(&cs->lock, flags);
  522. break;
  523. case (HW_DEACTIVATE | RESPONSE):
  524. skb_queue_purge(&cs->rq);
  525. skb_queue_purge(&cs->sq);
  526. if (cs->tx_skb) {
  527. dev_kfree_skb_any(cs->tx_skb);
  528. cs->tx_skb = NULL;
  529. }
  530. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  531. del_timer(&cs->dbusytimer);
  532. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  533. schedule_event(cs, D_CLEARBUSY);
  534. break;
  535. default:
  536. if (cs->debug & L1_DEB_WARN)
  537. debugl1(cs, "isac_l1hw unknown %04x", pr);
  538. break;
  539. }
  540. }
  541. static void
  542. setstack_isac(struct PStack *st, struct IsdnCardState *cs)
  543. {
  544. st->l1.l1hw = ISAC_l1hw;
  545. }
  546. static void
  547. DC_Close_isac(struct IsdnCardState *cs)
  548. {
  549. kfree(cs->dc.isac.mon_rx);
  550. cs->dc.isac.mon_rx = NULL;
  551. kfree(cs->dc.isac.mon_tx);
  552. cs->dc.isac.mon_tx = NULL;
  553. }
  554. static void
  555. dbusy_timer_handler(struct IsdnCardState *cs)
  556. {
  557. struct PStack *stptr;
  558. int rbch, star;
  559. if (test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
  560. rbch = cs->readisac(cs, ISAC_RBCH);
  561. star = cs->readisac(cs, ISAC_STAR);
  562. if (cs->debug)
  563. debugl1(cs, "D-Channel Busy RBCH %02x STAR %02x",
  564. rbch, star);
  565. if (rbch & ISAC_RBCH_XAC) { /* D-Channel Busy */
  566. test_and_set_bit(FLG_L1_DBUSY, &cs->HW_Flags);
  567. stptr = cs->stlist;
  568. while (stptr != NULL) {
  569. stptr->l1.l1l2(stptr, PH_PAUSE | INDICATION, NULL);
  570. stptr = stptr->next;
  571. }
  572. } else {
  573. /* discard frame; reset transceiver */
  574. test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags);
  575. if (cs->tx_skb) {
  576. dev_kfree_skb_any(cs->tx_skb);
  577. cs->tx_cnt = 0;
  578. cs->tx_skb = NULL;
  579. } else {
  580. printk(KERN_WARNING "HiSax: ISAC D-Channel Busy no skb\n");
  581. debugl1(cs, "D-Channel Busy no skb");
  582. }
  583. cs->writeisac(cs, ISAC_CMDR, 0x01); /* Transmitter reset */
  584. cs->irq_func(cs->irq, cs);
  585. }
  586. }
  587. }
  588. void initisac(struct IsdnCardState *cs)
  589. {
  590. cs->setstack_d = setstack_isac;
  591. cs->DC_Close = DC_Close_isac;
  592. cs->dc.isac.mon_tx = NULL;
  593. cs->dc.isac.mon_rx = NULL;
  594. cs->writeisac(cs, ISAC_MASK, 0xff);
  595. cs->dc.isac.mocr = 0xaa;
  596. if (test_bit(HW_IOM1, &cs->HW_Flags)) {
  597. /* IOM 1 Mode */
  598. cs->writeisac(cs, ISAC_ADF2, 0x0);
  599. cs->writeisac(cs, ISAC_SPCR, 0xa);
  600. cs->writeisac(cs, ISAC_ADF1, 0x2);
  601. cs->writeisac(cs, ISAC_STCR, 0x70);
  602. cs->writeisac(cs, ISAC_MODE, 0xc9);
  603. } else {
  604. /* IOM 2 Mode */
  605. if (!cs->dc.isac.adf2)
  606. cs->dc.isac.adf2 = 0x80;
  607. cs->writeisac(cs, ISAC_ADF2, cs->dc.isac.adf2);
  608. cs->writeisac(cs, ISAC_SQXR, 0x2f);
  609. cs->writeisac(cs, ISAC_SPCR, 0x00);
  610. cs->writeisac(cs, ISAC_STCR, 0x70);
  611. cs->writeisac(cs, ISAC_MODE, 0xc9);
  612. cs->writeisac(cs, ISAC_TIMR, 0x00);
  613. cs->writeisac(cs, ISAC_ADF1, 0x00);
  614. }
  615. ph_command(cs, ISAC_CMD_RS);
  616. cs->writeisac(cs, ISAC_MASK, 0x0);
  617. }
  618. void clear_pending_isac_ints(struct IsdnCardState *cs)
  619. {
  620. int val, eval;
  621. val = cs->readisac(cs, ISAC_STAR);
  622. debugl1(cs, "ISAC STAR %x", val);
  623. val = cs->readisac(cs, ISAC_MODE);
  624. debugl1(cs, "ISAC MODE %x", val);
  625. val = cs->readisac(cs, ISAC_ADF2);
  626. debugl1(cs, "ISAC ADF2 %x", val);
  627. val = cs->readisac(cs, ISAC_ISTA);
  628. debugl1(cs, "ISAC ISTA %x", val);
  629. if (val & 0x01) {
  630. eval = cs->readisac(cs, ISAC_EXIR);
  631. debugl1(cs, "ISAC EXIR %x", eval);
  632. }
  633. val = cs->readisac(cs, ISAC_CIR0);
  634. debugl1(cs, "ISAC CIR0 %x", val);
  635. cs->dc.isac.ph_state = (val >> 2) & 0xf;
  636. schedule_event(cs, D_L1STATECHANGE);
  637. /* Disable all IRQ */
  638. cs->writeisac(cs, ISAC_MASK, 0xFF);
  639. }
  640. void setup_isac(struct IsdnCardState *cs)
  641. {
  642. INIT_WORK(&cs->tqueue, isac_bh);
  643. cs->dbusytimer.function = (void *) dbusy_timer_handler;
  644. cs->dbusytimer.data = (long) cs;
  645. init_timer(&cs->dbusytimer);
  646. }