isac.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. count = cs->rcvidx;
  197. if (count > 0) {
  198. cs->rcvidx = 0;
  199. skb = alloc_skb(count, GFP_ATOMIC);
  200. if (!skb)
  201. printk(KERN_WARNING "HiSax: D receive out of memory\n");
  202. else {
  203. skb_put_data(skb, cs->rcvbuf, count);
  204. skb_queue_tail(&cs->rq, skb);
  205. }
  206. }
  207. }
  208. cs->rcvidx = 0;
  209. schedule_event(cs, D_RCVBUFREADY);
  210. }
  211. if (val & 0x40) { /* RPF */
  212. isac_empty_fifo(cs, 32);
  213. }
  214. if (val & 0x20) { /* RSC */
  215. /* never */
  216. if (cs->debug & L1_DEB_WARN)
  217. debugl1(cs, "ISAC RSC interrupt");
  218. }
  219. if (val & 0x10) { /* XPR */
  220. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  221. del_timer(&cs->dbusytimer);
  222. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  223. schedule_event(cs, D_CLEARBUSY);
  224. if (cs->tx_skb) {
  225. if (cs->tx_skb->len) {
  226. isac_fill_fifo(cs);
  227. goto afterXPR;
  228. } else {
  229. dev_kfree_skb_irq(cs->tx_skb);
  230. cs->tx_cnt = 0;
  231. cs->tx_skb = NULL;
  232. }
  233. }
  234. cs->tx_skb = skb_dequeue(&cs->sq);
  235. if (cs->tx_skb) {
  236. cs->tx_cnt = 0;
  237. isac_fill_fifo(cs);
  238. } else
  239. schedule_event(cs, D_XMTBUFREADY);
  240. }
  241. afterXPR:
  242. if (val & 0x04) { /* CISQ */
  243. exval = cs->readisac(cs, ISAC_CIR0);
  244. if (cs->debug & L1_DEB_ISAC)
  245. debugl1(cs, "ISAC CIR0 %02X", exval);
  246. if (exval & 2) {
  247. cs->dc.isac.ph_state = (exval >> 2) & 0xf;
  248. if (cs->debug & L1_DEB_ISAC)
  249. debugl1(cs, "ph_state change %x", cs->dc.isac.ph_state);
  250. schedule_event(cs, D_L1STATECHANGE);
  251. }
  252. if (exval & 1) {
  253. exval = cs->readisac(cs, ISAC_CIR1);
  254. if (cs->debug & L1_DEB_ISAC)
  255. debugl1(cs, "ISAC CIR1 %02X", exval);
  256. }
  257. }
  258. if (val & 0x02) { /* SIN */
  259. /* never */
  260. if (cs->debug & L1_DEB_WARN)
  261. debugl1(cs, "ISAC SIN interrupt");
  262. }
  263. if (val & 0x01) { /* EXI */
  264. exval = cs->readisac(cs, ISAC_EXIR);
  265. if (cs->debug & L1_DEB_WARN)
  266. debugl1(cs, "ISAC EXIR %02x", exval);
  267. if (exval & 0x80) { /* XMR */
  268. debugl1(cs, "ISAC XMR");
  269. printk(KERN_WARNING "HiSax: ISAC XMR\n");
  270. }
  271. if (exval & 0x40) { /* XDU */
  272. debugl1(cs, "ISAC XDU");
  273. printk(KERN_WARNING "HiSax: ISAC XDU\n");
  274. #ifdef ERROR_STATISTIC
  275. cs->err_tx++;
  276. #endif
  277. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  278. del_timer(&cs->dbusytimer);
  279. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  280. schedule_event(cs, D_CLEARBUSY);
  281. if (cs->tx_skb) { /* Restart frame */
  282. skb_push(cs->tx_skb, cs->tx_cnt);
  283. cs->tx_cnt = 0;
  284. isac_fill_fifo(cs);
  285. } else {
  286. printk(KERN_WARNING "HiSax: ISAC XDU no skb\n");
  287. debugl1(cs, "ISAC XDU no skb");
  288. }
  289. }
  290. if (exval & 0x04) { /* MOS */
  291. v1 = cs->readisac(cs, ISAC_MOSR);
  292. if (cs->debug & L1_DEB_MONITOR)
  293. debugl1(cs, "ISAC MOSR %02x", v1);
  294. #if ARCOFI_USE
  295. if (v1 & 0x08) {
  296. if (!cs->dc.isac.mon_rx) {
  297. cs->dc.isac.mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
  298. if (!cs->dc.isac.mon_rx) {
  299. if (cs->debug & L1_DEB_WARN)
  300. debugl1(cs, "ISAC MON RX out of memory!");
  301. cs->dc.isac.mocr &= 0xf0;
  302. cs->dc.isac.mocr |= 0x0a;
  303. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  304. goto afterMONR0;
  305. } else
  306. cs->dc.isac.mon_rxp = 0;
  307. }
  308. if (cs->dc.isac.mon_rxp >= MAX_MON_FRAME) {
  309. cs->dc.isac.mocr &= 0xf0;
  310. cs->dc.isac.mocr |= 0x0a;
  311. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  312. cs->dc.isac.mon_rxp = 0;
  313. if (cs->debug & L1_DEB_WARN)
  314. debugl1(cs, "ISAC MON RX overflow!");
  315. goto afterMONR0;
  316. }
  317. cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp++] = cs->readisac(cs, ISAC_MOR0);
  318. if (cs->debug & L1_DEB_MONITOR)
  319. debugl1(cs, "ISAC MOR0 %02x", cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp - 1]);
  320. if (cs->dc.isac.mon_rxp == 1) {
  321. cs->dc.isac.mocr |= 0x04;
  322. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  323. }
  324. }
  325. afterMONR0:
  326. if (v1 & 0x80) {
  327. if (!cs->dc.isac.mon_rx) {
  328. cs->dc.isac.mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
  329. if (!cs->dc.isac.mon_rx) {
  330. if (cs->debug & L1_DEB_WARN)
  331. debugl1(cs, "ISAC MON RX out of memory!");
  332. cs->dc.isac.mocr &= 0x0f;
  333. cs->dc.isac.mocr |= 0xa0;
  334. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  335. goto afterMONR1;
  336. } else
  337. cs->dc.isac.mon_rxp = 0;
  338. }
  339. if (cs->dc.isac.mon_rxp >= MAX_MON_FRAME) {
  340. cs->dc.isac.mocr &= 0x0f;
  341. cs->dc.isac.mocr |= 0xa0;
  342. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  343. cs->dc.isac.mon_rxp = 0;
  344. if (cs->debug & L1_DEB_WARN)
  345. debugl1(cs, "ISAC MON RX overflow!");
  346. goto afterMONR1;
  347. }
  348. cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp++] = cs->readisac(cs, ISAC_MOR1);
  349. if (cs->debug & L1_DEB_MONITOR)
  350. debugl1(cs, "ISAC MOR1 %02x", cs->dc.isac.mon_rx[cs->dc.isac.mon_rxp - 1]);
  351. cs->dc.isac.mocr |= 0x40;
  352. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  353. }
  354. afterMONR1:
  355. if (v1 & 0x04) {
  356. cs->dc.isac.mocr &= 0xf0;
  357. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  358. cs->dc.isac.mocr |= 0x0a;
  359. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  360. schedule_event(cs, D_RX_MON0);
  361. }
  362. if (v1 & 0x40) {
  363. cs->dc.isac.mocr &= 0x0f;
  364. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  365. cs->dc.isac.mocr |= 0xa0;
  366. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  367. schedule_event(cs, D_RX_MON1);
  368. }
  369. if (v1 & 0x02) {
  370. if ((!cs->dc.isac.mon_tx) || (cs->dc.isac.mon_txc &&
  371. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc) &&
  372. !(v1 & 0x08))) {
  373. cs->dc.isac.mocr &= 0xf0;
  374. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  375. cs->dc.isac.mocr |= 0x0a;
  376. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  377. if (cs->dc.isac.mon_txc &&
  378. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc))
  379. schedule_event(cs, D_TX_MON0);
  380. goto AfterMOX0;
  381. }
  382. if (cs->dc.isac.mon_txc && (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc)) {
  383. schedule_event(cs, D_TX_MON0);
  384. goto AfterMOX0;
  385. }
  386. cs->writeisac(cs, ISAC_MOX0,
  387. cs->dc.isac.mon_tx[cs->dc.isac.mon_txp++]);
  388. if (cs->debug & L1_DEB_MONITOR)
  389. debugl1(cs, "ISAC %02x -> MOX0", cs->dc.isac.mon_tx[cs->dc.isac.mon_txp - 1]);
  390. }
  391. AfterMOX0:
  392. if (v1 & 0x20) {
  393. if ((!cs->dc.isac.mon_tx) || (cs->dc.isac.mon_txc &&
  394. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc) &&
  395. !(v1 & 0x80))) {
  396. cs->dc.isac.mocr &= 0x0f;
  397. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  398. cs->dc.isac.mocr |= 0xa0;
  399. cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
  400. if (cs->dc.isac.mon_txc &&
  401. (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc))
  402. schedule_event(cs, D_TX_MON1);
  403. goto AfterMOX1;
  404. }
  405. if (cs->dc.isac.mon_txc && (cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc)) {
  406. schedule_event(cs, D_TX_MON1);
  407. goto AfterMOX1;
  408. }
  409. cs->writeisac(cs, ISAC_MOX1,
  410. cs->dc.isac.mon_tx[cs->dc.isac.mon_txp++]);
  411. if (cs->debug & L1_DEB_MONITOR)
  412. debugl1(cs, "ISAC %02x -> MOX1", cs->dc.isac.mon_tx[cs->dc.isac.mon_txp - 1]);
  413. }
  414. AfterMOX1:;
  415. #endif
  416. }
  417. }
  418. }
  419. static void
  420. ISAC_l1hw(struct PStack *st, int pr, void *arg)
  421. {
  422. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  423. struct sk_buff *skb = arg;
  424. u_long flags;
  425. int val;
  426. switch (pr) {
  427. case (PH_DATA | REQUEST):
  428. if (cs->debug & DEB_DLOG_HEX)
  429. LogFrame(cs, skb->data, skb->len);
  430. if (cs->debug & DEB_DLOG_VERBOSE)
  431. dlogframe(cs, skb, 0);
  432. spin_lock_irqsave(&cs->lock, flags);
  433. if (cs->tx_skb) {
  434. skb_queue_tail(&cs->sq, skb);
  435. #ifdef L2FRAME_DEBUG /* psa */
  436. if (cs->debug & L1_DEB_LAPD)
  437. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  438. #endif
  439. } else {
  440. cs->tx_skb = skb;
  441. cs->tx_cnt = 0;
  442. #ifdef L2FRAME_DEBUG /* psa */
  443. if (cs->debug & L1_DEB_LAPD)
  444. Logl2Frame(cs, skb, "PH_DATA", 0);
  445. #endif
  446. isac_fill_fifo(cs);
  447. }
  448. spin_unlock_irqrestore(&cs->lock, flags);
  449. break;
  450. case (PH_PULL | INDICATION):
  451. spin_lock_irqsave(&cs->lock, flags);
  452. if (cs->tx_skb) {
  453. if (cs->debug & L1_DEB_WARN)
  454. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  455. skb_queue_tail(&cs->sq, skb);
  456. } else {
  457. if (cs->debug & DEB_DLOG_HEX)
  458. LogFrame(cs, skb->data, skb->len);
  459. if (cs->debug & DEB_DLOG_VERBOSE)
  460. dlogframe(cs, skb, 0);
  461. cs->tx_skb = skb;
  462. cs->tx_cnt = 0;
  463. #ifdef L2FRAME_DEBUG /* psa */
  464. if (cs->debug & L1_DEB_LAPD)
  465. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  466. #endif
  467. isac_fill_fifo(cs);
  468. }
  469. spin_unlock_irqrestore(&cs->lock, flags);
  470. break;
  471. case (PH_PULL | REQUEST):
  472. #ifdef L2FRAME_DEBUG /* psa */
  473. if (cs->debug & L1_DEB_LAPD)
  474. debugl1(cs, "-> PH_REQUEST_PULL");
  475. #endif
  476. if (!cs->tx_skb) {
  477. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  478. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  479. } else
  480. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  481. break;
  482. case (HW_RESET | REQUEST):
  483. spin_lock_irqsave(&cs->lock, flags);
  484. if ((cs->dc.isac.ph_state == ISAC_IND_EI) ||
  485. (cs->dc.isac.ph_state == ISAC_IND_DR) ||
  486. (cs->dc.isac.ph_state == ISAC_IND_RS))
  487. ph_command(cs, ISAC_CMD_TIM);
  488. else
  489. ph_command(cs, ISAC_CMD_RS);
  490. spin_unlock_irqrestore(&cs->lock, flags);
  491. break;
  492. case (HW_ENABLE | REQUEST):
  493. spin_lock_irqsave(&cs->lock, flags);
  494. ph_command(cs, ISAC_CMD_TIM);
  495. spin_unlock_irqrestore(&cs->lock, flags);
  496. break;
  497. case (HW_INFO3 | REQUEST):
  498. spin_lock_irqsave(&cs->lock, flags);
  499. ph_command(cs, ISAC_CMD_AR8);
  500. spin_unlock_irqrestore(&cs->lock, flags);
  501. break;
  502. case (HW_TESTLOOP | REQUEST):
  503. spin_lock_irqsave(&cs->lock, flags);
  504. val = 0;
  505. if (1 & (long) arg)
  506. val |= 0x0c;
  507. if (2 & (long) arg)
  508. val |= 0x3;
  509. if (test_bit(HW_IOM1, &cs->HW_Flags)) {
  510. /* IOM 1 Mode */
  511. if (!val) {
  512. cs->writeisac(cs, ISAC_SPCR, 0xa);
  513. cs->writeisac(cs, ISAC_ADF1, 0x2);
  514. } else {
  515. cs->writeisac(cs, ISAC_SPCR, val);
  516. cs->writeisac(cs, ISAC_ADF1, 0xa);
  517. }
  518. } else {
  519. /* IOM 2 Mode */
  520. cs->writeisac(cs, ISAC_SPCR, val);
  521. if (val)
  522. cs->writeisac(cs, ISAC_ADF1, 0x8);
  523. else
  524. cs->writeisac(cs, ISAC_ADF1, 0x0);
  525. }
  526. spin_unlock_irqrestore(&cs->lock, flags);
  527. break;
  528. case (HW_DEACTIVATE | RESPONSE):
  529. skb_queue_purge(&cs->rq);
  530. skb_queue_purge(&cs->sq);
  531. if (cs->tx_skb) {
  532. dev_kfree_skb_any(cs->tx_skb);
  533. cs->tx_skb = NULL;
  534. }
  535. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  536. del_timer(&cs->dbusytimer);
  537. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  538. schedule_event(cs, D_CLEARBUSY);
  539. break;
  540. default:
  541. if (cs->debug & L1_DEB_WARN)
  542. debugl1(cs, "isac_l1hw unknown %04x", pr);
  543. break;
  544. }
  545. }
  546. static void
  547. setstack_isac(struct PStack *st, struct IsdnCardState *cs)
  548. {
  549. st->l1.l1hw = ISAC_l1hw;
  550. }
  551. static void
  552. DC_Close_isac(struct IsdnCardState *cs)
  553. {
  554. kfree(cs->dc.isac.mon_rx);
  555. cs->dc.isac.mon_rx = NULL;
  556. kfree(cs->dc.isac.mon_tx);
  557. cs->dc.isac.mon_tx = NULL;
  558. }
  559. static void
  560. dbusy_timer_handler(struct IsdnCardState *cs)
  561. {
  562. struct PStack *stptr;
  563. int rbch, star;
  564. if (test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
  565. rbch = cs->readisac(cs, ISAC_RBCH);
  566. star = cs->readisac(cs, ISAC_STAR);
  567. if (cs->debug)
  568. debugl1(cs, "D-Channel Busy RBCH %02x STAR %02x",
  569. rbch, star);
  570. if (rbch & ISAC_RBCH_XAC) { /* D-Channel Busy */
  571. test_and_set_bit(FLG_L1_DBUSY, &cs->HW_Flags);
  572. stptr = cs->stlist;
  573. while (stptr != NULL) {
  574. stptr->l1.l1l2(stptr, PH_PAUSE | INDICATION, NULL);
  575. stptr = stptr->next;
  576. }
  577. } else {
  578. /* discard frame; reset transceiver */
  579. test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags);
  580. if (cs->tx_skb) {
  581. dev_kfree_skb_any(cs->tx_skb);
  582. cs->tx_cnt = 0;
  583. cs->tx_skb = NULL;
  584. } else {
  585. printk(KERN_WARNING "HiSax: ISAC D-Channel Busy no skb\n");
  586. debugl1(cs, "D-Channel Busy no skb");
  587. }
  588. cs->writeisac(cs, ISAC_CMDR, 0x01); /* Transmitter reset */
  589. cs->irq_func(cs->irq, cs);
  590. }
  591. }
  592. }
  593. void initisac(struct IsdnCardState *cs)
  594. {
  595. cs->setstack_d = setstack_isac;
  596. cs->DC_Close = DC_Close_isac;
  597. cs->dc.isac.mon_tx = NULL;
  598. cs->dc.isac.mon_rx = NULL;
  599. cs->writeisac(cs, ISAC_MASK, 0xff);
  600. cs->dc.isac.mocr = 0xaa;
  601. if (test_bit(HW_IOM1, &cs->HW_Flags)) {
  602. /* IOM 1 Mode */
  603. cs->writeisac(cs, ISAC_ADF2, 0x0);
  604. cs->writeisac(cs, ISAC_SPCR, 0xa);
  605. cs->writeisac(cs, ISAC_ADF1, 0x2);
  606. cs->writeisac(cs, ISAC_STCR, 0x70);
  607. cs->writeisac(cs, ISAC_MODE, 0xc9);
  608. } else {
  609. /* IOM 2 Mode */
  610. if (!cs->dc.isac.adf2)
  611. cs->dc.isac.adf2 = 0x80;
  612. cs->writeisac(cs, ISAC_ADF2, cs->dc.isac.adf2);
  613. cs->writeisac(cs, ISAC_SQXR, 0x2f);
  614. cs->writeisac(cs, ISAC_SPCR, 0x00);
  615. cs->writeisac(cs, ISAC_STCR, 0x70);
  616. cs->writeisac(cs, ISAC_MODE, 0xc9);
  617. cs->writeisac(cs, ISAC_TIMR, 0x00);
  618. cs->writeisac(cs, ISAC_ADF1, 0x00);
  619. }
  620. ph_command(cs, ISAC_CMD_RS);
  621. cs->writeisac(cs, ISAC_MASK, 0x0);
  622. }
  623. void clear_pending_isac_ints(struct IsdnCardState *cs)
  624. {
  625. int val, eval;
  626. val = cs->readisac(cs, ISAC_STAR);
  627. debugl1(cs, "ISAC STAR %x", val);
  628. val = cs->readisac(cs, ISAC_MODE);
  629. debugl1(cs, "ISAC MODE %x", val);
  630. val = cs->readisac(cs, ISAC_ADF2);
  631. debugl1(cs, "ISAC ADF2 %x", val);
  632. val = cs->readisac(cs, ISAC_ISTA);
  633. debugl1(cs, "ISAC ISTA %x", val);
  634. if (val & 0x01) {
  635. eval = cs->readisac(cs, ISAC_EXIR);
  636. debugl1(cs, "ISAC EXIR %x", eval);
  637. }
  638. val = cs->readisac(cs, ISAC_CIR0);
  639. debugl1(cs, "ISAC CIR0 %x", val);
  640. cs->dc.isac.ph_state = (val >> 2) & 0xf;
  641. schedule_event(cs, D_L1STATECHANGE);
  642. /* Disable all IRQ */
  643. cs->writeisac(cs, ISAC_MASK, 0xFF);
  644. }
  645. void setup_isac(struct IsdnCardState *cs)
  646. {
  647. INIT_WORK(&cs->tqueue, isac_bh);
  648. setup_timer(&cs->dbusytimer, (void *)dbusy_timer_handler, (long)cs);
  649. }