isdnl1.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. /* $Id: isdnl1.c,v 2.46.2.5 2004/02/11 13:21:34 keil Exp $
  2. *
  3. * common low level stuff for Siemens Chipsetbased isdn cards
  4. *
  5. * Author Karsten Keil
  6. * based on the teles driver from Jan den Ouden
  7. * Copyright by Karsten Keil <keil@isdn4linux.de>
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. * For changes and modifications please read
  13. * Documentation/isdn/HiSax.cert
  14. *
  15. * Thanks to Jan den Ouden
  16. * Fritz Elfert
  17. * Beat Doebeli
  18. *
  19. */
  20. const char *l1_revision = "$Revision: 2.46.2.5 $";
  21. #include <linux/init.h>
  22. #include "hisax.h"
  23. #include "isdnl1.h"
  24. #define TIMER3_VALUE 7000
  25. static struct Fsm l1fsm_b;
  26. static struct Fsm l1fsm_s;
  27. enum {
  28. ST_L1_F2,
  29. ST_L1_F3,
  30. ST_L1_F4,
  31. ST_L1_F5,
  32. ST_L1_F6,
  33. ST_L1_F7,
  34. ST_L1_F8,
  35. };
  36. #define L1S_STATE_COUNT (ST_L1_F8+1)
  37. static char *strL1SState[] =
  38. {
  39. "ST_L1_F2",
  40. "ST_L1_F3",
  41. "ST_L1_F4",
  42. "ST_L1_F5",
  43. "ST_L1_F6",
  44. "ST_L1_F7",
  45. "ST_L1_F8",
  46. };
  47. #ifdef HISAX_UINTERFACE
  48. static
  49. struct Fsm l1fsm_u =
  50. {NULL, 0, 0, NULL, NULL};
  51. enum {
  52. ST_L1_RESET,
  53. ST_L1_DEACT,
  54. ST_L1_SYNC2,
  55. ST_L1_TRANS,
  56. };
  57. #define L1U_STATE_COUNT (ST_L1_TRANS+1)
  58. static char *strL1UState[] =
  59. {
  60. "ST_L1_RESET",
  61. "ST_L1_DEACT",
  62. "ST_L1_SYNC2",
  63. "ST_L1_TRANS",
  64. };
  65. #endif
  66. enum {
  67. ST_L1_NULL,
  68. ST_L1_WAIT_ACT,
  69. ST_L1_WAIT_DEACT,
  70. ST_L1_ACTIV,
  71. };
  72. #define L1B_STATE_COUNT (ST_L1_ACTIV+1)
  73. static char *strL1BState[] =
  74. {
  75. "ST_L1_NULL",
  76. "ST_L1_WAIT_ACT",
  77. "ST_L1_WAIT_DEACT",
  78. "ST_L1_ACTIV",
  79. };
  80. enum {
  81. EV_PH_ACTIVATE,
  82. EV_PH_DEACTIVATE,
  83. EV_RESET_IND,
  84. EV_DEACT_CNF,
  85. EV_DEACT_IND,
  86. EV_POWER_UP,
  87. EV_RSYNC_IND,
  88. EV_INFO2_IND,
  89. EV_INFO4_IND,
  90. EV_TIMER_DEACT,
  91. EV_TIMER_ACT,
  92. EV_TIMER3,
  93. };
  94. #define L1_EVENT_COUNT (EV_TIMER3 + 1)
  95. static char *strL1Event[] =
  96. {
  97. "EV_PH_ACTIVATE",
  98. "EV_PH_DEACTIVATE",
  99. "EV_RESET_IND",
  100. "EV_DEACT_CNF",
  101. "EV_DEACT_IND",
  102. "EV_POWER_UP",
  103. "EV_RSYNC_IND",
  104. "EV_INFO2_IND",
  105. "EV_INFO4_IND",
  106. "EV_TIMER_DEACT",
  107. "EV_TIMER_ACT",
  108. "EV_TIMER3",
  109. };
  110. void
  111. debugl1(struct IsdnCardState *cs, char *fmt, ...)
  112. {
  113. va_list args;
  114. char tmp[8];
  115. va_start(args, fmt);
  116. sprintf(tmp, "Card%d ", cs->cardnr + 1);
  117. VHiSax_putstatus(cs, tmp, fmt, args);
  118. va_end(args);
  119. }
  120. static void
  121. l1m_debug(struct FsmInst *fi, char *fmt, ...)
  122. {
  123. va_list args;
  124. struct PStack *st = fi->userdata;
  125. struct IsdnCardState *cs = st->l1.hardware;
  126. char tmp[8];
  127. va_start(args, fmt);
  128. sprintf(tmp, "Card%d ", cs->cardnr + 1);
  129. VHiSax_putstatus(cs, tmp, fmt, args);
  130. va_end(args);
  131. }
  132. static void
  133. L1activated(struct IsdnCardState *cs)
  134. {
  135. struct PStack *st;
  136. st = cs->stlist;
  137. while (st) {
  138. if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  139. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  140. else
  141. st->l1.l1l2(st, PH_ACTIVATE | INDICATION, NULL);
  142. st = st->next;
  143. }
  144. }
  145. static void
  146. L1deactivated(struct IsdnCardState *cs)
  147. {
  148. struct PStack *st;
  149. st = cs->stlist;
  150. while (st) {
  151. if (test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  152. st->l1.l1l2(st, PH_PAUSE | CONFIRM, NULL);
  153. st->l1.l1l2(st, PH_DEACTIVATE | INDICATION, NULL);
  154. st = st->next;
  155. }
  156. test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
  157. }
  158. void
  159. DChannel_proc_xmt(struct IsdnCardState *cs)
  160. {
  161. struct PStack *stptr;
  162. if (cs->tx_skb)
  163. return;
  164. stptr = cs->stlist;
  165. while (stptr != NULL) {
  166. if (test_and_clear_bit(FLG_L1_PULL_REQ, &stptr->l1.Flags)) {
  167. stptr->l1.l1l2(stptr, PH_PULL | CONFIRM, NULL);
  168. break;
  169. } else
  170. stptr = stptr->next;
  171. }
  172. }
  173. void
  174. DChannel_proc_rcv(struct IsdnCardState *cs)
  175. {
  176. struct sk_buff *skb, *nskb;
  177. struct PStack *stptr = cs->stlist;
  178. int found, tei, sapi;
  179. if (stptr)
  180. if (test_bit(FLG_L1_ACTTIMER, &stptr->l1.Flags))
  181. FsmEvent(&stptr->l1.l1m, EV_TIMER_ACT, NULL);
  182. while ((skb = skb_dequeue(&cs->rq))) {
  183. #ifdef L2FRAME_DEBUG /* psa */
  184. if (cs->debug & L1_DEB_LAPD)
  185. Logl2Frame(cs, skb, "PH_DATA", 1);
  186. #endif
  187. stptr = cs->stlist;
  188. if (skb->len<3) {
  189. debugl1(cs, "D-channel frame too short(%d)",skb->len);
  190. dev_kfree_skb(skb);
  191. return;
  192. }
  193. if ((skb->data[0] & 1) || !(skb->data[1] &1)) {
  194. debugl1(cs, "D-channel frame wrong EA0/EA1");
  195. dev_kfree_skb(skb);
  196. return;
  197. }
  198. sapi = skb->data[0] >> 2;
  199. tei = skb->data[1] >> 1;
  200. if (cs->debug & DEB_DLOG_HEX)
  201. LogFrame(cs, skb->data, skb->len);
  202. if (cs->debug & DEB_DLOG_VERBOSE)
  203. dlogframe(cs, skb, 1);
  204. if (tei == GROUP_TEI) {
  205. if (sapi == CTRL_SAPI) { /* sapi 0 */
  206. while (stptr != NULL) {
  207. if ((nskb = skb_clone(skb, GFP_ATOMIC)))
  208. stptr->l1.l1l2(stptr, PH_DATA | INDICATION, nskb);
  209. else
  210. printk(KERN_WARNING "HiSax: isdn broadcast buffer shortage\n");
  211. stptr = stptr->next;
  212. }
  213. } else if (sapi == TEI_SAPI) {
  214. while (stptr != NULL) {
  215. if ((nskb = skb_clone(skb, GFP_ATOMIC)))
  216. stptr->l1.l1tei(stptr, PH_DATA | INDICATION, nskb);
  217. else
  218. printk(KERN_WARNING "HiSax: tei broadcast buffer shortage\n");
  219. stptr = stptr->next;
  220. }
  221. }
  222. dev_kfree_skb(skb);
  223. } else if (sapi == CTRL_SAPI) { /* sapi 0 */
  224. found = 0;
  225. while (stptr != NULL)
  226. if (tei == stptr->l2.tei) {
  227. stptr->l1.l1l2(stptr, PH_DATA | INDICATION, skb);
  228. found = !0;
  229. break;
  230. } else
  231. stptr = stptr->next;
  232. if (!found)
  233. dev_kfree_skb(skb);
  234. } else
  235. dev_kfree_skb(skb);
  236. }
  237. }
  238. static void
  239. BChannel_proc_xmt(struct BCState *bcs)
  240. {
  241. struct PStack *st = bcs->st;
  242. if (test_bit(BC_FLG_BUSY, &bcs->Flag)) {
  243. debugl1(bcs->cs, "BC_BUSY Error");
  244. return;
  245. }
  246. if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags))
  247. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  248. if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) {
  249. if (!test_bit(BC_FLG_BUSY, &bcs->Flag) &&
  250. skb_queue_empty(&bcs->squeue)) {
  251. st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
  252. }
  253. }
  254. }
  255. static void
  256. BChannel_proc_rcv(struct BCState *bcs)
  257. {
  258. struct sk_buff *skb;
  259. if (bcs->st->l1.l1m.state == ST_L1_WAIT_ACT) {
  260. FsmDelTimer(&bcs->st->l1.timer, 4);
  261. FsmEvent(&bcs->st->l1.l1m, EV_TIMER_ACT, NULL);
  262. }
  263. while ((skb = skb_dequeue(&bcs->rqueue))) {
  264. bcs->st->l1.l1l2(bcs->st, PH_DATA | INDICATION, skb);
  265. }
  266. }
  267. static void
  268. BChannel_proc_ack(struct BCState *bcs)
  269. {
  270. u_long flags;
  271. int ack;
  272. spin_lock_irqsave(&bcs->aclock, flags);
  273. ack = bcs->ackcnt;
  274. bcs->ackcnt = 0;
  275. spin_unlock_irqrestore(&bcs->aclock, flags);
  276. if (ack)
  277. lli_writewakeup(bcs->st, ack);
  278. }
  279. void
  280. BChannel_bh(struct BCState *bcs)
  281. {
  282. if (!bcs)
  283. return;
  284. if (test_and_clear_bit(B_RCVBUFREADY, &bcs->event))
  285. BChannel_proc_rcv(bcs);
  286. if (test_and_clear_bit(B_XMTBUFREADY, &bcs->event))
  287. BChannel_proc_xmt(bcs);
  288. if (test_and_clear_bit(B_ACKPENDING, &bcs->event))
  289. BChannel_proc_ack(bcs);
  290. }
  291. void
  292. HiSax_addlist(struct IsdnCardState *cs,
  293. struct PStack *st)
  294. {
  295. st->next = cs->stlist;
  296. cs->stlist = st;
  297. }
  298. void
  299. HiSax_rmlist(struct IsdnCardState *cs,
  300. struct PStack *st)
  301. {
  302. struct PStack *p;
  303. FsmDelTimer(&st->l1.timer, 0);
  304. if (cs->stlist == st)
  305. cs->stlist = st->next;
  306. else {
  307. p = cs->stlist;
  308. while (p)
  309. if (p->next == st) {
  310. p->next = st->next;
  311. return;
  312. } else
  313. p = p->next;
  314. }
  315. }
  316. void
  317. init_bcstate(struct IsdnCardState *cs, int bc)
  318. {
  319. struct BCState *bcs = cs->bcs + bc;
  320. bcs->cs = cs;
  321. bcs->channel = bc;
  322. INIT_WORK(&bcs->tqueue, (void *)(void *) BChannel_bh, bcs);
  323. spin_lock_init(&bcs->aclock);
  324. bcs->BC_SetStack = NULL;
  325. bcs->BC_Close = NULL;
  326. bcs->Flag = 0;
  327. }
  328. #ifdef L2FRAME_DEBUG /* psa */
  329. static char *
  330. l2cmd(u_char cmd)
  331. {
  332. switch (cmd & ~0x10) {
  333. case 1:
  334. return "RR";
  335. case 5:
  336. return "RNR";
  337. case 9:
  338. return "REJ";
  339. case 0x6f:
  340. return "SABME";
  341. case 0x0f:
  342. return "DM";
  343. case 3:
  344. return "UI";
  345. case 0x43:
  346. return "DISC";
  347. case 0x63:
  348. return "UA";
  349. case 0x87:
  350. return "FRMR";
  351. case 0xaf:
  352. return "XID";
  353. default:
  354. if (!(cmd & 1))
  355. return "I";
  356. else
  357. return "invalid command";
  358. }
  359. }
  360. static char tmpdeb[32];
  361. static char *
  362. l2frames(u_char * ptr)
  363. {
  364. switch (ptr[2] & ~0x10) {
  365. case 1:
  366. case 5:
  367. case 9:
  368. sprintf(tmpdeb, "%s[%d](nr %d)", l2cmd(ptr[2]), ptr[3] & 1, ptr[3] >> 1);
  369. break;
  370. case 0x6f:
  371. case 0x0f:
  372. case 3:
  373. case 0x43:
  374. case 0x63:
  375. case 0x87:
  376. case 0xaf:
  377. sprintf(tmpdeb, "%s[%d]", l2cmd(ptr[2]), (ptr[2] & 0x10) >> 4);
  378. break;
  379. default:
  380. if (!(ptr[2] & 1)) {
  381. sprintf(tmpdeb, "I[%d](ns %d, nr %d)", ptr[3] & 1, ptr[2] >> 1, ptr[3] >> 1);
  382. break;
  383. } else
  384. return "invalid command";
  385. }
  386. return tmpdeb;
  387. }
  388. void
  389. Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir)
  390. {
  391. u_char *ptr;
  392. ptr = skb->data;
  393. if (ptr[0] & 1 || !(ptr[1] & 1))
  394. debugl1(cs, "Address not LAPD");
  395. else
  396. debugl1(cs, "%s %s: %s%c (sapi %d, tei %d)",
  397. (dir ? "<-" : "->"), buf, l2frames(ptr),
  398. ((ptr[0] & 2) >> 1) == dir ? 'C' : 'R', ptr[0] >> 2, ptr[1] >> 1);
  399. }
  400. #endif
  401. static void
  402. l1_reset(struct FsmInst *fi, int event, void *arg)
  403. {
  404. FsmChangeState(fi, ST_L1_F3);
  405. }
  406. static void
  407. l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
  408. {
  409. struct PStack *st = fi->userdata;
  410. FsmChangeState(fi, ST_L1_F3);
  411. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  412. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  413. }
  414. static void
  415. l1_deact_req_s(struct FsmInst *fi, int event, void *arg)
  416. {
  417. struct PStack *st = fi->userdata;
  418. FsmChangeState(fi, ST_L1_F3);
  419. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  420. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  421. }
  422. static void
  423. l1_power_up_s(struct FsmInst *fi, int event, void *arg)
  424. {
  425. struct PStack *st = fi->userdata;
  426. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags)) {
  427. FsmChangeState(fi, ST_L1_F4);
  428. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  429. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  430. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  431. } else
  432. FsmChangeState(fi, ST_L1_F3);
  433. }
  434. static void
  435. l1_go_F5(struct FsmInst *fi, int event, void *arg)
  436. {
  437. FsmChangeState(fi, ST_L1_F5);
  438. }
  439. static void
  440. l1_go_F8(struct FsmInst *fi, int event, void *arg)
  441. {
  442. FsmChangeState(fi, ST_L1_F8);
  443. }
  444. static void
  445. l1_info2_ind(struct FsmInst *fi, int event, void *arg)
  446. {
  447. struct PStack *st = fi->userdata;
  448. #ifdef HISAX_UINTERFACE
  449. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  450. FsmChangeState(fi, ST_L1_SYNC2);
  451. else
  452. #endif
  453. FsmChangeState(fi, ST_L1_F6);
  454. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  455. }
  456. static void
  457. l1_info4_ind(struct FsmInst *fi, int event, void *arg)
  458. {
  459. struct PStack *st = fi->userdata;
  460. #ifdef HISAX_UINTERFACE
  461. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  462. FsmChangeState(fi, ST_L1_TRANS);
  463. else
  464. #endif
  465. FsmChangeState(fi, ST_L1_F7);
  466. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  467. if (test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags))
  468. FsmDelTimer(&st->l1.timer, 4);
  469. if (!test_bit(FLG_L1_ACTIVATED, &st->l1.Flags)) {
  470. if (test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags))
  471. FsmDelTimer(&st->l1.timer, 3);
  472. FsmRestartTimer(&st->l1.timer, 110, EV_TIMER_ACT, NULL, 2);
  473. test_and_set_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  474. }
  475. }
  476. static void
  477. l1_timer3(struct FsmInst *fi, int event, void *arg)
  478. {
  479. struct PStack *st = fi->userdata;
  480. test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags);
  481. if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  482. L1deactivated(st->l1.hardware);
  483. #ifdef HISAX_UINTERFACE
  484. if (!test_bit(FLG_L1_UINT, &st->l1.Flags))
  485. #endif
  486. if (st->l1.l1m.state != ST_L1_F6) {
  487. FsmChangeState(fi, ST_L1_F3);
  488. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  489. }
  490. }
  491. static void
  492. l1_timer_act(struct FsmInst *fi, int event, void *arg)
  493. {
  494. struct PStack *st = fi->userdata;
  495. test_and_clear_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  496. test_and_set_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  497. L1activated(st->l1.hardware);
  498. }
  499. static void
  500. l1_timer_deact(struct FsmInst *fi, int event, void *arg)
  501. {
  502. struct PStack *st = fi->userdata;
  503. test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  504. test_and_clear_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  505. L1deactivated(st->l1.hardware);
  506. st->l1.l1hw(st, HW_DEACTIVATE | RESPONSE, NULL);
  507. }
  508. static void
  509. l1_activate_s(struct FsmInst *fi, int event, void *arg)
  510. {
  511. struct PStack *st = fi->userdata;
  512. st->l1.l1hw(st, HW_RESET | REQUEST, NULL);
  513. }
  514. static void
  515. l1_activate_no(struct FsmInst *fi, int event, void *arg)
  516. {
  517. struct PStack *st = fi->userdata;
  518. if ((!test_bit(FLG_L1_DEACTTIMER, &st->l1.Flags)) && (!test_bit(FLG_L1_T3RUN, &st->l1.Flags))) {
  519. test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
  520. L1deactivated(st->l1.hardware);
  521. }
  522. }
  523. static struct FsmNode L1SFnList[] __initdata =
  524. {
  525. {ST_L1_F3, EV_PH_ACTIVATE, l1_activate_s},
  526. {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
  527. {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
  528. {ST_L1_F3, EV_RESET_IND, l1_reset},
  529. {ST_L1_F4, EV_RESET_IND, l1_reset},
  530. {ST_L1_F5, EV_RESET_IND, l1_reset},
  531. {ST_L1_F6, EV_RESET_IND, l1_reset},
  532. {ST_L1_F7, EV_RESET_IND, l1_reset},
  533. {ST_L1_F8, EV_RESET_IND, l1_reset},
  534. {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
  535. {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
  536. {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
  537. {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
  538. {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
  539. {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
  540. {ST_L1_F6, EV_DEACT_IND, l1_deact_req_s},
  541. {ST_L1_F7, EV_DEACT_IND, l1_deact_req_s},
  542. {ST_L1_F8, EV_DEACT_IND, l1_deact_req_s},
  543. {ST_L1_F3, EV_POWER_UP, l1_power_up_s},
  544. {ST_L1_F4, EV_RSYNC_IND, l1_go_F5},
  545. {ST_L1_F6, EV_RSYNC_IND, l1_go_F8},
  546. {ST_L1_F7, EV_RSYNC_IND, l1_go_F8},
  547. {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
  548. {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
  549. {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
  550. {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
  551. {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
  552. {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
  553. {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
  554. {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
  555. {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
  556. {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
  557. {ST_L1_F3, EV_TIMER3, l1_timer3},
  558. {ST_L1_F4, EV_TIMER3, l1_timer3},
  559. {ST_L1_F5, EV_TIMER3, l1_timer3},
  560. {ST_L1_F6, EV_TIMER3, l1_timer3},
  561. {ST_L1_F8, EV_TIMER3, l1_timer3},
  562. {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
  563. {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
  564. {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
  565. {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
  566. {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
  567. {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
  568. {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
  569. };
  570. #define L1S_FN_COUNT (sizeof(L1SFnList)/sizeof(struct FsmNode))
  571. #ifdef HISAX_UINTERFACE
  572. static void
  573. l1_deact_req_u(struct FsmInst *fi, int event, void *arg)
  574. {
  575. struct PStack *st = fi->userdata;
  576. FsmChangeState(fi, ST_L1_RESET);
  577. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  578. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  579. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  580. }
  581. static void
  582. l1_power_up_u(struct FsmInst *fi, int event, void *arg)
  583. {
  584. struct PStack *st = fi->userdata;
  585. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  586. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  587. }
  588. static void
  589. l1_info0_ind(struct FsmInst *fi, int event, void *arg)
  590. {
  591. FsmChangeState(fi, ST_L1_DEACT);
  592. }
  593. static void
  594. l1_activate_u(struct FsmInst *fi, int event, void *arg)
  595. {
  596. struct PStack *st = fi->userdata;
  597. st->l1.l1hw(st, HW_INFO1 | REQUEST, NULL);
  598. }
  599. static struct FsmNode L1UFnList[] __initdata =
  600. {
  601. {ST_L1_RESET, EV_DEACT_IND, l1_deact_req_u},
  602. {ST_L1_DEACT, EV_DEACT_IND, l1_deact_req_u},
  603. {ST_L1_SYNC2, EV_DEACT_IND, l1_deact_req_u},
  604. {ST_L1_TRANS, EV_DEACT_IND, l1_deact_req_u},
  605. {ST_L1_DEACT, EV_PH_ACTIVATE, l1_activate_u},
  606. {ST_L1_DEACT, EV_POWER_UP, l1_power_up_u},
  607. {ST_L1_DEACT, EV_INFO2_IND, l1_info2_ind},
  608. {ST_L1_TRANS, EV_INFO2_IND, l1_info2_ind},
  609. {ST_L1_RESET, EV_DEACT_CNF, l1_info0_ind},
  610. {ST_L1_DEACT, EV_INFO4_IND, l1_info4_ind},
  611. {ST_L1_SYNC2, EV_INFO4_IND, l1_info4_ind},
  612. {ST_L1_RESET, EV_INFO4_IND, l1_info4_ind},
  613. {ST_L1_DEACT, EV_TIMER3, l1_timer3},
  614. {ST_L1_SYNC2, EV_TIMER3, l1_timer3},
  615. {ST_L1_TRANS, EV_TIMER_ACT, l1_timer_act},
  616. {ST_L1_DEACT, EV_TIMER_DEACT, l1_timer_deact},
  617. {ST_L1_SYNC2, EV_TIMER_DEACT, l1_timer_deact},
  618. {ST_L1_RESET, EV_TIMER_DEACT, l1_timer_deact},
  619. };
  620. #define L1U_FN_COUNT (sizeof(L1UFnList)/sizeof(struct FsmNode))
  621. #endif
  622. static void
  623. l1b_activate(struct FsmInst *fi, int event, void *arg)
  624. {
  625. struct PStack *st = fi->userdata;
  626. FsmChangeState(fi, ST_L1_WAIT_ACT);
  627. FsmRestartTimer(&st->l1.timer, st->l1.delay, EV_TIMER_ACT, NULL, 2);
  628. }
  629. static void
  630. l1b_deactivate(struct FsmInst *fi, int event, void *arg)
  631. {
  632. struct PStack *st = fi->userdata;
  633. FsmChangeState(fi, ST_L1_WAIT_DEACT);
  634. FsmRestartTimer(&st->l1.timer, 10, EV_TIMER_DEACT, NULL, 2);
  635. }
  636. static void
  637. l1b_timer_act(struct FsmInst *fi, int event, void *arg)
  638. {
  639. struct PStack *st = fi->userdata;
  640. FsmChangeState(fi, ST_L1_ACTIV);
  641. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  642. }
  643. static void
  644. l1b_timer_deact(struct FsmInst *fi, int event, void *arg)
  645. {
  646. struct PStack *st = fi->userdata;
  647. FsmChangeState(fi, ST_L1_NULL);
  648. st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
  649. }
  650. static struct FsmNode L1BFnList[] __initdata =
  651. {
  652. {ST_L1_NULL, EV_PH_ACTIVATE, l1b_activate},
  653. {ST_L1_WAIT_ACT, EV_TIMER_ACT, l1b_timer_act},
  654. {ST_L1_ACTIV, EV_PH_DEACTIVATE, l1b_deactivate},
  655. {ST_L1_WAIT_DEACT, EV_TIMER_DEACT, l1b_timer_deact},
  656. };
  657. #define L1B_FN_COUNT (sizeof(L1BFnList)/sizeof(struct FsmNode))
  658. int __init
  659. Isdnl1New(void)
  660. {
  661. int retval;
  662. l1fsm_s.state_count = L1S_STATE_COUNT;
  663. l1fsm_s.event_count = L1_EVENT_COUNT;
  664. l1fsm_s.strEvent = strL1Event;
  665. l1fsm_s.strState = strL1SState;
  666. retval = FsmNew(&l1fsm_s, L1SFnList, L1S_FN_COUNT);
  667. if (retval)
  668. return retval;
  669. l1fsm_b.state_count = L1B_STATE_COUNT;
  670. l1fsm_b.event_count = L1_EVENT_COUNT;
  671. l1fsm_b.strEvent = strL1Event;
  672. l1fsm_b.strState = strL1BState;
  673. retval = FsmNew(&l1fsm_b, L1BFnList, L1B_FN_COUNT);
  674. if (retval) {
  675. FsmFree(&l1fsm_s);
  676. return retval;
  677. }
  678. #ifdef HISAX_UINTERFACE
  679. l1fsm_u.state_count = L1U_STATE_COUNT;
  680. l1fsm_u.event_count = L1_EVENT_COUNT;
  681. l1fsm_u.strEvent = strL1Event;
  682. l1fsm_u.strState = strL1UState;
  683. retval = FsmNew(&l1fsm_u, L1UFnList, L1U_FN_COUNT);
  684. if (retval) {
  685. FsmFree(&l1fsm_s);
  686. FsmFree(&l1fsm_b);
  687. return retval;
  688. }
  689. #endif
  690. return 0;
  691. }
  692. void Isdnl1Free(void)
  693. {
  694. #ifdef HISAX_UINTERFACE
  695. FsmFree(&l1fsm_u);
  696. #endif
  697. FsmFree(&l1fsm_s);
  698. FsmFree(&l1fsm_b);
  699. }
  700. static void
  701. dch_l2l1(struct PStack *st, int pr, void *arg)
  702. {
  703. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  704. switch (pr) {
  705. case (PH_DATA | REQUEST):
  706. case (PH_PULL | REQUEST):
  707. case (PH_PULL |INDICATION):
  708. st->l1.l1hw(st, pr, arg);
  709. break;
  710. case (PH_ACTIVATE | REQUEST):
  711. if (cs->debug)
  712. debugl1(cs, "PH_ACTIVATE_REQ %s",
  713. st->l1.l1m.fsm->strState[st->l1.l1m.state]);
  714. if (test_bit(FLG_L1_ACTIVATED, &st->l1.Flags))
  715. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  716. else {
  717. test_and_set_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
  718. FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, arg);
  719. }
  720. break;
  721. case (PH_TESTLOOP | REQUEST):
  722. if (1 & (long) arg)
  723. debugl1(cs, "PH_TEST_LOOP B1");
  724. if (2 & (long) arg)
  725. debugl1(cs, "PH_TEST_LOOP B2");
  726. if (!(3 & (long) arg))
  727. debugl1(cs, "PH_TEST_LOOP DISABLED");
  728. st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
  729. break;
  730. default:
  731. if (cs->debug)
  732. debugl1(cs, "dch_l2l1 msg %04X unhandled", pr);
  733. break;
  734. }
  735. }
  736. void
  737. l1_msg(struct IsdnCardState *cs, int pr, void *arg) {
  738. struct PStack *st;
  739. st = cs->stlist;
  740. while (st) {
  741. switch(pr) {
  742. case (HW_RESET | INDICATION):
  743. FsmEvent(&st->l1.l1m, EV_RESET_IND, arg);
  744. break;
  745. case (HW_DEACTIVATE | CONFIRM):
  746. FsmEvent(&st->l1.l1m, EV_DEACT_CNF, arg);
  747. break;
  748. case (HW_DEACTIVATE | INDICATION):
  749. FsmEvent(&st->l1.l1m, EV_DEACT_IND, arg);
  750. break;
  751. case (HW_POWERUP | CONFIRM):
  752. FsmEvent(&st->l1.l1m, EV_POWER_UP, arg);
  753. break;
  754. case (HW_RSYNC | INDICATION):
  755. FsmEvent(&st->l1.l1m, EV_RSYNC_IND, arg);
  756. break;
  757. case (HW_INFO2 | INDICATION):
  758. FsmEvent(&st->l1.l1m, EV_INFO2_IND, arg);
  759. break;
  760. case (HW_INFO4_P8 | INDICATION):
  761. case (HW_INFO4_P10 | INDICATION):
  762. FsmEvent(&st->l1.l1m, EV_INFO4_IND, arg);
  763. break;
  764. default:
  765. if (cs->debug)
  766. debugl1(cs, "l1msg %04X unhandled", pr);
  767. break;
  768. }
  769. st = st->next;
  770. }
  771. }
  772. void
  773. l1_msg_b(struct PStack *st, int pr, void *arg) {
  774. switch(pr) {
  775. case (PH_ACTIVATE | REQUEST):
  776. FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, NULL);
  777. break;
  778. case (PH_DEACTIVATE | REQUEST):
  779. FsmEvent(&st->l1.l1m, EV_PH_DEACTIVATE, NULL);
  780. break;
  781. }
  782. }
  783. void
  784. setstack_HiSax(struct PStack *st, struct IsdnCardState *cs)
  785. {
  786. st->l1.hardware = cs;
  787. st->protocol = cs->protocol;
  788. st->l1.l1m.fsm = &l1fsm_s;
  789. st->l1.l1m.state = ST_L1_F3;
  790. st->l1.Flags = 0;
  791. #ifdef HISAX_UINTERFACE
  792. if (test_bit(FLG_HW_L1_UINT, &cs->HW_Flags)) {
  793. st->l1.l1m.fsm = &l1fsm_u;
  794. st->l1.l1m.state = ST_L1_RESET;
  795. st->l1.Flags = FLG_L1_UINT;
  796. }
  797. #endif
  798. st->l1.l1m.debug = cs->debug;
  799. st->l1.l1m.userdata = st;
  800. st->l1.l1m.userint = 0;
  801. st->l1.l1m.printdebug = l1m_debug;
  802. FsmInitTimer(&st->l1.l1m, &st->l1.timer);
  803. setstack_tei(st);
  804. setstack_manager(st);
  805. st->l1.stlistp = &(cs->stlist);
  806. st->l2.l2l1 = dch_l2l1;
  807. if (cs->setstack_d)
  808. cs->setstack_d(st, cs);
  809. }
  810. void
  811. setstack_l1_B(struct PStack *st)
  812. {
  813. struct IsdnCardState *cs = st->l1.hardware;
  814. st->l1.l1m.fsm = &l1fsm_b;
  815. st->l1.l1m.state = ST_L1_NULL;
  816. st->l1.l1m.debug = cs->debug;
  817. st->l1.l1m.userdata = st;
  818. st->l1.l1m.userint = 0;
  819. st->l1.l1m.printdebug = l1m_debug;
  820. st->l1.Flags = 0;
  821. FsmInitTimer(&st->l1.l1m, &st->l1.timer);
  822. }