queue.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /******************************************************************************
  2. *
  3. * (C)Copyright 1998,1999 SysKonnect,
  4. * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
  5. *
  6. * See the file "skfddi.c" for further information.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * The information in this file is provided "AS IS" without warranty.
  14. *
  15. ******************************************************************************/
  16. /*
  17. SMT Event Queue Management
  18. */
  19. #include "h/types.h"
  20. #include "h/fddi.h"
  21. #include "h/smc.h"
  22. #ifndef lint
  23. static const char ID_sccs[] = "@(#)queue.c 2.9 97/08/04 (C) SK " ;
  24. #endif
  25. #define PRINTF(a,b,c)
  26. /*
  27. * init event queue management
  28. */
  29. void ev_init(struct s_smc *smc)
  30. {
  31. smc->q.ev_put = smc->q.ev_get = smc->q.ev_queue ;
  32. }
  33. /*
  34. * add event to queue
  35. */
  36. void queue_event(struct s_smc *smc, int class, int event)
  37. {
  38. PRINTF("queue class %d event %d\n",class,event) ;
  39. smc->q.ev_put->class = class ;
  40. smc->q.ev_put->event = event ;
  41. if (++smc->q.ev_put == &smc->q.ev_queue[MAX_EVENT])
  42. smc->q.ev_put = smc->q.ev_queue ;
  43. if (smc->q.ev_put == smc->q.ev_get) {
  44. SMT_ERR_LOG(smc,SMT_E0137, SMT_E0137_MSG) ;
  45. }
  46. }
  47. /*
  48. * timer_event is called from HW timer package.
  49. */
  50. void timer_event(struct s_smc *smc, u_long token)
  51. {
  52. PRINTF("timer event class %d token %d\n",
  53. EV_T_CLASS(token),
  54. EV_T_EVENT(token)) ;
  55. queue_event(smc,EV_T_CLASS(token),EV_T_EVENT(token));
  56. }
  57. /*
  58. * event dispatcher
  59. * while event queue is not empty
  60. * get event from queue
  61. * send command to state machine
  62. * end
  63. */
  64. void ev_dispatcher(struct s_smc *smc)
  65. {
  66. struct event_queue *ev ; /* pointer into queue */
  67. int class ;
  68. ev = smc->q.ev_get ;
  69. PRINTF("dispatch get %x put %x\n",ev,smc->q.ev_put) ;
  70. while (ev != smc->q.ev_put) {
  71. PRINTF("dispatch class %d event %d\n",ev->class,ev->event) ;
  72. switch(class = ev->class) {
  73. case EVENT_ECM : /* Entity Corordination Man. */
  74. ecm(smc,(int)ev->event) ;
  75. break ;
  76. case EVENT_CFM : /* Configuration Man. */
  77. cfm(smc,(int)ev->event) ;
  78. break ;
  79. case EVENT_RMT : /* Ring Man. */
  80. rmt(smc,(int)ev->event) ;
  81. break ;
  82. case EVENT_SMT :
  83. smt_event(smc,(int)ev->event) ;
  84. break ;
  85. #ifdef CONCENTRATOR
  86. case 99 :
  87. timer_test_event(smc,(int)ev->event) ;
  88. break ;
  89. #endif
  90. case EVENT_PCMA : /* PHY A */
  91. case EVENT_PCMB : /* PHY B */
  92. default :
  93. if (class >= EVENT_PCMA &&
  94. class < EVENT_PCMA + NUMPHYS) {
  95. pcm(smc,class - EVENT_PCMA,(int)ev->event) ;
  96. break ;
  97. }
  98. SMT_PANIC(smc,SMT_E0121, SMT_E0121_MSG) ;
  99. return ;
  100. }
  101. if (++ev == &smc->q.ev_queue[MAX_EVENT])
  102. ev = smc->q.ev_queue ;
  103. /* Renew get: it is used in queue_events to detect overruns */
  104. smc->q.ev_get = ev;
  105. }
  106. }
  107. /*
  108. * smt_online connects to or disconnects from the ring
  109. * MUST be called to initiate connection establishment
  110. *
  111. * on 0 disconnect
  112. * on 1 connect
  113. */
  114. u_short smt_online(struct s_smc *smc, int on)
  115. {
  116. queue_event(smc,EVENT_ECM,on ? EC_CONNECT : EC_DISCONNECT) ;
  117. ev_dispatcher(smc) ;
  118. return smc->mib.fddiSMTCF_State;
  119. }
  120. /*
  121. * set SMT flag to value
  122. * flag flag name
  123. * value flag value
  124. * dump current flag setting
  125. */
  126. #ifdef CONCENTRATOR
  127. void do_smt_flag(struct s_smc *smc, char *flag, int value)
  128. {
  129. #ifdef DEBUG
  130. struct smt_debug *deb;
  131. SK_UNUSED(smc) ;
  132. #ifdef DEBUG_BRD
  133. deb = &smc->debug;
  134. #else
  135. deb = &debug;
  136. #endif
  137. if (!strcmp(flag,"smt"))
  138. deb->d_smt = value ;
  139. else if (!strcmp(flag,"smtf"))
  140. deb->d_smtf = value ;
  141. else if (!strcmp(flag,"pcm"))
  142. deb->d_pcm = value ;
  143. else if (!strcmp(flag,"rmt"))
  144. deb->d_rmt = value ;
  145. else if (!strcmp(flag,"cfm"))
  146. deb->d_cfm = value ;
  147. else if (!strcmp(flag,"ecm"))
  148. deb->d_ecm = value ;
  149. printf("smt %d\n",deb->d_smt) ;
  150. printf("smtf %d\n",deb->d_smtf) ;
  151. printf("pcm %d\n",deb->d_pcm) ;
  152. printf("rmt %d\n",deb->d_rmt) ;
  153. printf("cfm %d\n",deb->d_cfm) ;
  154. printf("ecm %d\n",deb->d_ecm) ;
  155. #endif /* DEBUG */
  156. }
  157. #endif