isdnl1.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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 work_struct *work)
  281. {
  282. struct BCState *bcs = container_of(work, struct BCState, tqueue);
  283. if (!bcs)
  284. return;
  285. if (test_and_clear_bit(B_RCVBUFREADY, &bcs->event))
  286. BChannel_proc_rcv(bcs);
  287. if (test_and_clear_bit(B_XMTBUFREADY, &bcs->event))
  288. BChannel_proc_xmt(bcs);
  289. if (test_and_clear_bit(B_ACKPENDING, &bcs->event))
  290. BChannel_proc_ack(bcs);
  291. }
  292. void
  293. HiSax_addlist(struct IsdnCardState *cs,
  294. struct PStack *st)
  295. {
  296. st->next = cs->stlist;
  297. cs->stlist = st;
  298. }
  299. void
  300. HiSax_rmlist(struct IsdnCardState *cs,
  301. struct PStack *st)
  302. {
  303. struct PStack *p;
  304. FsmDelTimer(&st->l1.timer, 0);
  305. if (cs->stlist == st)
  306. cs->stlist = st->next;
  307. else {
  308. p = cs->stlist;
  309. while (p)
  310. if (p->next == st) {
  311. p->next = st->next;
  312. return;
  313. } else
  314. p = p->next;
  315. }
  316. }
  317. void
  318. init_bcstate(struct IsdnCardState *cs, int bc)
  319. {
  320. struct BCState *bcs = cs->bcs + bc;
  321. bcs->cs = cs;
  322. bcs->channel = bc;
  323. INIT_WORK(&bcs->tqueue, BChannel_bh);
  324. spin_lock_init(&bcs->aclock);
  325. bcs->BC_SetStack = NULL;
  326. bcs->BC_Close = NULL;
  327. bcs->Flag = 0;
  328. }
  329. #ifdef L2FRAME_DEBUG /* psa */
  330. static char *
  331. l2cmd(u_char cmd)
  332. {
  333. switch (cmd & ~0x10) {
  334. case 1:
  335. return "RR";
  336. case 5:
  337. return "RNR";
  338. case 9:
  339. return "REJ";
  340. case 0x6f:
  341. return "SABME";
  342. case 0x0f:
  343. return "DM";
  344. case 3:
  345. return "UI";
  346. case 0x43:
  347. return "DISC";
  348. case 0x63:
  349. return "UA";
  350. case 0x87:
  351. return "FRMR";
  352. case 0xaf:
  353. return "XID";
  354. default:
  355. if (!(cmd & 1))
  356. return "I";
  357. else
  358. return "invalid command";
  359. }
  360. }
  361. static char tmpdeb[32];
  362. static char *
  363. l2frames(u_char * ptr)
  364. {
  365. switch (ptr[2] & ~0x10) {
  366. case 1:
  367. case 5:
  368. case 9:
  369. sprintf(tmpdeb, "%s[%d](nr %d)", l2cmd(ptr[2]), ptr[3] & 1, ptr[3] >> 1);
  370. break;
  371. case 0x6f:
  372. case 0x0f:
  373. case 3:
  374. case 0x43:
  375. case 0x63:
  376. case 0x87:
  377. case 0xaf:
  378. sprintf(tmpdeb, "%s[%d]", l2cmd(ptr[2]), (ptr[2] & 0x10) >> 4);
  379. break;
  380. default:
  381. if (!(ptr[2] & 1)) {
  382. sprintf(tmpdeb, "I[%d](ns %d, nr %d)", ptr[3] & 1, ptr[2] >> 1, ptr[3] >> 1);
  383. break;
  384. } else
  385. return "invalid command";
  386. }
  387. return tmpdeb;
  388. }
  389. void
  390. Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir)
  391. {
  392. u_char *ptr;
  393. ptr = skb->data;
  394. if (ptr[0] & 1 || !(ptr[1] & 1))
  395. debugl1(cs, "Address not LAPD");
  396. else
  397. debugl1(cs, "%s %s: %s%c (sapi %d, tei %d)",
  398. (dir ? "<-" : "->"), buf, l2frames(ptr),
  399. ((ptr[0] & 2) >> 1) == dir ? 'C' : 'R', ptr[0] >> 2, ptr[1] >> 1);
  400. }
  401. #endif
  402. static void
  403. l1_reset(struct FsmInst *fi, int event, void *arg)
  404. {
  405. FsmChangeState(fi, ST_L1_F3);
  406. }
  407. static void
  408. l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
  409. {
  410. struct PStack *st = fi->userdata;
  411. FsmChangeState(fi, ST_L1_F3);
  412. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  413. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  414. }
  415. static void
  416. l1_deact_req_s(struct FsmInst *fi, int event, void *arg)
  417. {
  418. struct PStack *st = fi->userdata;
  419. FsmChangeState(fi, ST_L1_F3);
  420. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  421. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  422. }
  423. static void
  424. l1_power_up_s(struct FsmInst *fi, int event, void *arg)
  425. {
  426. struct PStack *st = fi->userdata;
  427. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags)) {
  428. FsmChangeState(fi, ST_L1_F4);
  429. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  430. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  431. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  432. } else
  433. FsmChangeState(fi, ST_L1_F3);
  434. }
  435. static void
  436. l1_go_F5(struct FsmInst *fi, int event, void *arg)
  437. {
  438. FsmChangeState(fi, ST_L1_F5);
  439. }
  440. static void
  441. l1_go_F8(struct FsmInst *fi, int event, void *arg)
  442. {
  443. FsmChangeState(fi, ST_L1_F8);
  444. }
  445. static void
  446. l1_info2_ind(struct FsmInst *fi, int event, void *arg)
  447. {
  448. struct PStack *st = fi->userdata;
  449. #ifdef HISAX_UINTERFACE
  450. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  451. FsmChangeState(fi, ST_L1_SYNC2);
  452. else
  453. #endif
  454. FsmChangeState(fi, ST_L1_F6);
  455. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  456. }
  457. static void
  458. l1_info4_ind(struct FsmInst *fi, int event, void *arg)
  459. {
  460. struct PStack *st = fi->userdata;
  461. #ifdef HISAX_UINTERFACE
  462. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  463. FsmChangeState(fi, ST_L1_TRANS);
  464. else
  465. #endif
  466. FsmChangeState(fi, ST_L1_F7);
  467. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  468. if (test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags))
  469. FsmDelTimer(&st->l1.timer, 4);
  470. if (!test_bit(FLG_L1_ACTIVATED, &st->l1.Flags)) {
  471. if (test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags))
  472. FsmDelTimer(&st->l1.timer, 3);
  473. FsmRestartTimer(&st->l1.timer, 110, EV_TIMER_ACT, NULL, 2);
  474. test_and_set_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  475. }
  476. }
  477. static void
  478. l1_timer3(struct FsmInst *fi, int event, void *arg)
  479. {
  480. struct PStack *st = fi->userdata;
  481. test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags);
  482. if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  483. L1deactivated(st->l1.hardware);
  484. #ifdef HISAX_UINTERFACE
  485. if (!test_bit(FLG_L1_UINT, &st->l1.Flags))
  486. #endif
  487. if (st->l1.l1m.state != ST_L1_F6) {
  488. FsmChangeState(fi, ST_L1_F3);
  489. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  490. }
  491. }
  492. static void
  493. l1_timer_act(struct FsmInst *fi, int event, void *arg)
  494. {
  495. struct PStack *st = fi->userdata;
  496. test_and_clear_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  497. test_and_set_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  498. L1activated(st->l1.hardware);
  499. }
  500. static void
  501. l1_timer_deact(struct FsmInst *fi, int event, void *arg)
  502. {
  503. struct PStack *st = fi->userdata;
  504. test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  505. test_and_clear_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  506. L1deactivated(st->l1.hardware);
  507. st->l1.l1hw(st, HW_DEACTIVATE | RESPONSE, NULL);
  508. }
  509. static void
  510. l1_activate_s(struct FsmInst *fi, int event, void *arg)
  511. {
  512. struct PStack *st = fi->userdata;
  513. st->l1.l1hw(st, HW_RESET | REQUEST, NULL);
  514. }
  515. static void
  516. l1_activate_no(struct FsmInst *fi, int event, void *arg)
  517. {
  518. struct PStack *st = fi->userdata;
  519. if ((!test_bit(FLG_L1_DEACTTIMER, &st->l1.Flags)) && (!test_bit(FLG_L1_T3RUN, &st->l1.Flags))) {
  520. test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
  521. L1deactivated(st->l1.hardware);
  522. }
  523. }
  524. static struct FsmNode L1SFnList[] __initdata =
  525. {
  526. {ST_L1_F3, EV_PH_ACTIVATE, l1_activate_s},
  527. {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
  528. {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
  529. {ST_L1_F3, EV_RESET_IND, l1_reset},
  530. {ST_L1_F4, EV_RESET_IND, l1_reset},
  531. {ST_L1_F5, EV_RESET_IND, l1_reset},
  532. {ST_L1_F6, EV_RESET_IND, l1_reset},
  533. {ST_L1_F7, EV_RESET_IND, l1_reset},
  534. {ST_L1_F8, EV_RESET_IND, l1_reset},
  535. {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
  536. {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
  537. {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
  538. {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
  539. {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
  540. {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
  541. {ST_L1_F6, EV_DEACT_IND, l1_deact_req_s},
  542. {ST_L1_F7, EV_DEACT_IND, l1_deact_req_s},
  543. {ST_L1_F8, EV_DEACT_IND, l1_deact_req_s},
  544. {ST_L1_F3, EV_POWER_UP, l1_power_up_s},
  545. {ST_L1_F4, EV_RSYNC_IND, l1_go_F5},
  546. {ST_L1_F6, EV_RSYNC_IND, l1_go_F8},
  547. {ST_L1_F7, EV_RSYNC_IND, l1_go_F8},
  548. {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
  549. {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
  550. {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
  551. {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
  552. {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
  553. {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
  554. {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
  555. {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
  556. {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
  557. {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
  558. {ST_L1_F3, EV_TIMER3, l1_timer3},
  559. {ST_L1_F4, EV_TIMER3, l1_timer3},
  560. {ST_L1_F5, EV_TIMER3, l1_timer3},
  561. {ST_L1_F6, EV_TIMER3, l1_timer3},
  562. {ST_L1_F8, EV_TIMER3, l1_timer3},
  563. {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
  564. {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
  565. {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
  566. {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
  567. {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
  568. {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
  569. {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
  570. };
  571. #define L1S_FN_COUNT (sizeof(L1SFnList)/sizeof(struct FsmNode))
  572. #ifdef HISAX_UINTERFACE
  573. static void
  574. l1_deact_req_u(struct FsmInst *fi, int event, void *arg)
  575. {
  576. struct PStack *st = fi->userdata;
  577. FsmChangeState(fi, ST_L1_RESET);
  578. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  579. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  580. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  581. }
  582. static void
  583. l1_power_up_u(struct FsmInst *fi, int event, void *arg)
  584. {
  585. struct PStack *st = fi->userdata;
  586. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  587. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  588. }
  589. static void
  590. l1_info0_ind(struct FsmInst *fi, int event, void *arg)
  591. {
  592. FsmChangeState(fi, ST_L1_DEACT);
  593. }
  594. static void
  595. l1_activate_u(struct FsmInst *fi, int event, void *arg)
  596. {
  597. struct PStack *st = fi->userdata;
  598. st->l1.l1hw(st, HW_INFO1 | REQUEST, NULL);
  599. }
  600. static struct FsmNode L1UFnList[] __initdata =
  601. {
  602. {ST_L1_RESET, EV_DEACT_IND, l1_deact_req_u},
  603. {ST_L1_DEACT, EV_DEACT_IND, l1_deact_req_u},
  604. {ST_L1_SYNC2, EV_DEACT_IND, l1_deact_req_u},
  605. {ST_L1_TRANS, EV_DEACT_IND, l1_deact_req_u},
  606. {ST_L1_DEACT, EV_PH_ACTIVATE, l1_activate_u},
  607. {ST_L1_DEACT, EV_POWER_UP, l1_power_up_u},
  608. {ST_L1_DEACT, EV_INFO2_IND, l1_info2_ind},
  609. {ST_L1_TRANS, EV_INFO2_IND, l1_info2_ind},
  610. {ST_L1_RESET, EV_DEACT_CNF, l1_info0_ind},
  611. {ST_L1_DEACT, EV_INFO4_IND, l1_info4_ind},
  612. {ST_L1_SYNC2, EV_INFO4_IND, l1_info4_ind},
  613. {ST_L1_RESET, EV_INFO4_IND, l1_info4_ind},
  614. {ST_L1_DEACT, EV_TIMER3, l1_timer3},
  615. {ST_L1_SYNC2, EV_TIMER3, l1_timer3},
  616. {ST_L1_TRANS, EV_TIMER_ACT, l1_timer_act},
  617. {ST_L1_DEACT, EV_TIMER_DEACT, l1_timer_deact},
  618. {ST_L1_SYNC2, EV_TIMER_DEACT, l1_timer_deact},
  619. {ST_L1_RESET, EV_TIMER_DEACT, l1_timer_deact},
  620. };
  621. #define L1U_FN_COUNT (sizeof(L1UFnList)/sizeof(struct FsmNode))
  622. #endif
  623. static void
  624. l1b_activate(struct FsmInst *fi, int event, void *arg)
  625. {
  626. struct PStack *st = fi->userdata;
  627. FsmChangeState(fi, ST_L1_WAIT_ACT);
  628. FsmRestartTimer(&st->l1.timer, st->l1.delay, EV_TIMER_ACT, NULL, 2);
  629. }
  630. static void
  631. l1b_deactivate(struct FsmInst *fi, int event, void *arg)
  632. {
  633. struct PStack *st = fi->userdata;
  634. FsmChangeState(fi, ST_L1_WAIT_DEACT);
  635. FsmRestartTimer(&st->l1.timer, 10, EV_TIMER_DEACT, NULL, 2);
  636. }
  637. static void
  638. l1b_timer_act(struct FsmInst *fi, int event, void *arg)
  639. {
  640. struct PStack *st = fi->userdata;
  641. FsmChangeState(fi, ST_L1_ACTIV);
  642. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  643. }
  644. static void
  645. l1b_timer_deact(struct FsmInst *fi, int event, void *arg)
  646. {
  647. struct PStack *st = fi->userdata;
  648. FsmChangeState(fi, ST_L1_NULL);
  649. st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
  650. }
  651. static struct FsmNode L1BFnList[] __initdata =
  652. {
  653. {ST_L1_NULL, EV_PH_ACTIVATE, l1b_activate},
  654. {ST_L1_WAIT_ACT, EV_TIMER_ACT, l1b_timer_act},
  655. {ST_L1_ACTIV, EV_PH_DEACTIVATE, l1b_deactivate},
  656. {ST_L1_WAIT_DEACT, EV_TIMER_DEACT, l1b_timer_deact},
  657. };
  658. #define L1B_FN_COUNT (sizeof(L1BFnList)/sizeof(struct FsmNode))
  659. int __init
  660. Isdnl1New(void)
  661. {
  662. int retval;
  663. l1fsm_s.state_count = L1S_STATE_COUNT;
  664. l1fsm_s.event_count = L1_EVENT_COUNT;
  665. l1fsm_s.strEvent = strL1Event;
  666. l1fsm_s.strState = strL1SState;
  667. retval = FsmNew(&l1fsm_s, L1SFnList, L1S_FN_COUNT);
  668. if (retval)
  669. return retval;
  670. l1fsm_b.state_count = L1B_STATE_COUNT;
  671. l1fsm_b.event_count = L1_EVENT_COUNT;
  672. l1fsm_b.strEvent = strL1Event;
  673. l1fsm_b.strState = strL1BState;
  674. retval = FsmNew(&l1fsm_b, L1BFnList, L1B_FN_COUNT);
  675. if (retval) {
  676. FsmFree(&l1fsm_s);
  677. return retval;
  678. }
  679. #ifdef HISAX_UINTERFACE
  680. l1fsm_u.state_count = L1U_STATE_COUNT;
  681. l1fsm_u.event_count = L1_EVENT_COUNT;
  682. l1fsm_u.strEvent = strL1Event;
  683. l1fsm_u.strState = strL1UState;
  684. retval = FsmNew(&l1fsm_u, L1UFnList, L1U_FN_COUNT);
  685. if (retval) {
  686. FsmFree(&l1fsm_s);
  687. FsmFree(&l1fsm_b);
  688. return retval;
  689. }
  690. #endif
  691. return 0;
  692. }
  693. void Isdnl1Free(void)
  694. {
  695. #ifdef HISAX_UINTERFACE
  696. FsmFree(&l1fsm_u);
  697. #endif
  698. FsmFree(&l1fsm_s);
  699. FsmFree(&l1fsm_b);
  700. }
  701. static void
  702. dch_l2l1(struct PStack *st, int pr, void *arg)
  703. {
  704. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  705. switch (pr) {
  706. case (PH_DATA | REQUEST):
  707. case (PH_PULL | REQUEST):
  708. case (PH_PULL |INDICATION):
  709. st->l1.l1hw(st, pr, arg);
  710. break;
  711. case (PH_ACTIVATE | REQUEST):
  712. if (cs->debug)
  713. debugl1(cs, "PH_ACTIVATE_REQ %s",
  714. st->l1.l1m.fsm->strState[st->l1.l1m.state]);
  715. if (test_bit(FLG_L1_ACTIVATED, &st->l1.Flags))
  716. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  717. else {
  718. test_and_set_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
  719. FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, arg);
  720. }
  721. break;
  722. case (PH_TESTLOOP | REQUEST):
  723. if (1 & (long) arg)
  724. debugl1(cs, "PH_TEST_LOOP B1");
  725. if (2 & (long) arg)
  726. debugl1(cs, "PH_TEST_LOOP B2");
  727. if (!(3 & (long) arg))
  728. debugl1(cs, "PH_TEST_LOOP DISABLED");
  729. st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
  730. break;
  731. default:
  732. if (cs->debug)
  733. debugl1(cs, "dch_l2l1 msg %04X unhandled", pr);
  734. break;
  735. }
  736. }
  737. void
  738. l1_msg(struct IsdnCardState *cs, int pr, void *arg) {
  739. struct PStack *st;
  740. st = cs->stlist;
  741. while (st) {
  742. switch(pr) {
  743. case (HW_RESET | INDICATION):
  744. FsmEvent(&st->l1.l1m, EV_RESET_IND, arg);
  745. break;
  746. case (HW_DEACTIVATE | CONFIRM):
  747. FsmEvent(&st->l1.l1m, EV_DEACT_CNF, arg);
  748. break;
  749. case (HW_DEACTIVATE | INDICATION):
  750. FsmEvent(&st->l1.l1m, EV_DEACT_IND, arg);
  751. break;
  752. case (HW_POWERUP | CONFIRM):
  753. FsmEvent(&st->l1.l1m, EV_POWER_UP, arg);
  754. break;
  755. case (HW_RSYNC | INDICATION):
  756. FsmEvent(&st->l1.l1m, EV_RSYNC_IND, arg);
  757. break;
  758. case (HW_INFO2 | INDICATION):
  759. FsmEvent(&st->l1.l1m, EV_INFO2_IND, arg);
  760. break;
  761. case (HW_INFO4_P8 | INDICATION):
  762. case (HW_INFO4_P10 | INDICATION):
  763. FsmEvent(&st->l1.l1m, EV_INFO4_IND, arg);
  764. break;
  765. default:
  766. if (cs->debug)
  767. debugl1(cs, "l1msg %04X unhandled", pr);
  768. break;
  769. }
  770. st = st->next;
  771. }
  772. }
  773. void
  774. l1_msg_b(struct PStack *st, int pr, void *arg) {
  775. switch(pr) {
  776. case (PH_ACTIVATE | REQUEST):
  777. FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, NULL);
  778. break;
  779. case (PH_DEACTIVATE | REQUEST):
  780. FsmEvent(&st->l1.l1m, EV_PH_DEACTIVATE, NULL);
  781. break;
  782. }
  783. }
  784. void
  785. setstack_HiSax(struct PStack *st, struct IsdnCardState *cs)
  786. {
  787. st->l1.hardware = cs;
  788. st->protocol = cs->protocol;
  789. st->l1.l1m.fsm = &l1fsm_s;
  790. st->l1.l1m.state = ST_L1_F3;
  791. st->l1.Flags = 0;
  792. #ifdef HISAX_UINTERFACE
  793. if (test_bit(FLG_HW_L1_UINT, &cs->HW_Flags)) {
  794. st->l1.l1m.fsm = &l1fsm_u;
  795. st->l1.l1m.state = ST_L1_RESET;
  796. st->l1.Flags = FLG_L1_UINT;
  797. }
  798. #endif
  799. st->l1.l1m.debug = cs->debug;
  800. st->l1.l1m.userdata = st;
  801. st->l1.l1m.userint = 0;
  802. st->l1.l1m.printdebug = l1m_debug;
  803. FsmInitTimer(&st->l1.l1m, &st->l1.timer);
  804. setstack_tei(st);
  805. setstack_manager(st);
  806. st->l1.stlistp = &(cs->stlist);
  807. st->l2.l2l1 = dch_l2l1;
  808. if (cs->setstack_d)
  809. cs->setstack_d(st, cs);
  810. }
  811. void
  812. setstack_l1_B(struct PStack *st)
  813. {
  814. struct IsdnCardState *cs = st->l1.hardware;
  815. st->l1.l1m.fsm = &l1fsm_b;
  816. st->l1.l1m.state = ST_L1_NULL;
  817. st->l1.l1m.debug = cs->debug;
  818. st->l1.l1m.userdata = st;
  819. st->l1.l1m.userint = 0;
  820. st->l1.l1m.printdebug = l1m_debug;
  821. st->l1.Flags = 0;
  822. FsmInitTimer(&st->l1.l1m, &st->l1.timer);
  823. }