srf.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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 7.2 Status Response Frame Implementation
  18. SRF state machine and frame generation
  19. */
  20. #include "h/types.h"
  21. #include "h/fddi.h"
  22. #include "h/smc.h"
  23. #include "h/smt_p.h"
  24. #define KERNEL
  25. #include "h/smtstate.h"
  26. #ifndef SLIM_SMT
  27. #ifndef BOOT
  28. #ifndef lint
  29. static const char ID_sccs[] = "@(#)srf.c 1.18 97/08/04 (C) SK " ;
  30. #endif
  31. /*
  32. * function declarations
  33. */
  34. static void clear_all_rep(struct s_smc *smc);
  35. static void clear_reported(struct s_smc *smc);
  36. static void smt_send_srf(struct s_smc *smc);
  37. static struct s_srf_evc *smt_get_evc(struct s_smc *smc, int code, int index);
  38. #define MAX_EVCS ARRAY_SIZE(smc->evcs)
  39. struct evc_init {
  40. u_char code ;
  41. u_char index ;
  42. u_char n ;
  43. u_short para ;
  44. } ;
  45. static const struct evc_init evc_inits[] = {
  46. { SMT_COND_SMT_PEER_WRAP, 0,1,SMT_P1048 } ,
  47. { SMT_COND_MAC_DUP_ADDR, INDEX_MAC, NUMMACS,SMT_P208C } ,
  48. { SMT_COND_MAC_FRAME_ERROR, INDEX_MAC, NUMMACS,SMT_P208D } ,
  49. { SMT_COND_MAC_NOT_COPIED, INDEX_MAC, NUMMACS,SMT_P208E } ,
  50. { SMT_EVENT_MAC_NEIGHBOR_CHANGE, INDEX_MAC, NUMMACS,SMT_P208F } ,
  51. { SMT_EVENT_MAC_PATH_CHANGE, INDEX_MAC, NUMMACS,SMT_P2090 } ,
  52. { SMT_COND_PORT_LER, INDEX_PORT,NUMPHYS,SMT_P4050 } ,
  53. { SMT_COND_PORT_EB_ERROR, INDEX_PORT,NUMPHYS,SMT_P4052 } ,
  54. { SMT_EVENT_PORT_CONNECTION, INDEX_PORT,NUMPHYS,SMT_P4051 } ,
  55. { SMT_EVENT_PORT_PATH_CHANGE, INDEX_PORT,NUMPHYS,SMT_P4053 } ,
  56. } ;
  57. #define MAX_INIT_EVC ARRAY_SIZE(evc_inits)
  58. void smt_init_evc(struct s_smc *smc)
  59. {
  60. struct s_srf_evc *evc ;
  61. const struct evc_init *init ;
  62. int i ;
  63. int index ;
  64. int offset ;
  65. static u_char fail_safe = FALSE ;
  66. memset((char *)smc->evcs,0,sizeof(smc->evcs)) ;
  67. evc = smc->evcs ;
  68. init = evc_inits ;
  69. for (i = 0 ; (unsigned) i < MAX_INIT_EVC ; i++) {
  70. for (index = 0 ; index < init->n ; index++) {
  71. evc->evc_code = init->code ;
  72. evc->evc_para = init->para ;
  73. evc->evc_index = init->index + index ;
  74. #ifndef DEBUG
  75. evc->evc_multiple = &fail_safe ;
  76. evc->evc_cond_state = &fail_safe ;
  77. #endif
  78. evc++ ;
  79. }
  80. init++ ;
  81. }
  82. if ((unsigned) (evc - smc->evcs) > MAX_EVCS) {
  83. SMT_PANIC(smc,SMT_E0127, SMT_E0127_MSG) ;
  84. }
  85. /*
  86. * conditions
  87. */
  88. smc->evcs[0].evc_cond_state = &smc->mib.fddiSMTPeerWrapFlag ;
  89. smc->evcs[1].evc_cond_state =
  90. &smc->mib.m[MAC0].fddiMACDuplicateAddressCond ;
  91. smc->evcs[2].evc_cond_state =
  92. &smc->mib.m[MAC0].fddiMACFrameErrorFlag ;
  93. smc->evcs[3].evc_cond_state =
  94. &smc->mib.m[MAC0].fddiMACNotCopiedFlag ;
  95. /*
  96. * events
  97. */
  98. smc->evcs[4].evc_multiple = &smc->mib.m[MAC0].fddiMACMultiple_N ;
  99. smc->evcs[5].evc_multiple = &smc->mib.m[MAC0].fddiMACMultiple_P ;
  100. offset = 6 ;
  101. for (i = 0 ; i < NUMPHYS ; i++) {
  102. /*
  103. * conditions
  104. */
  105. smc->evcs[offset + 0*NUMPHYS].evc_cond_state =
  106. &smc->mib.p[i].fddiPORTLerFlag ;
  107. smc->evcs[offset + 1*NUMPHYS].evc_cond_state =
  108. &smc->mib.p[i].fddiPORTEB_Condition ;
  109. /*
  110. * events
  111. */
  112. smc->evcs[offset + 2*NUMPHYS].evc_multiple =
  113. &smc->mib.p[i].fddiPORTMultiple_U ;
  114. smc->evcs[offset + 3*NUMPHYS].evc_multiple =
  115. &smc->mib.p[i].fddiPORTMultiple_P ;
  116. offset++ ;
  117. }
  118. #ifdef DEBUG
  119. for (i = 0, evc = smc->evcs ; (unsigned) i < MAX_EVCS ; i++, evc++) {
  120. if (SMT_IS_CONDITION(evc->evc_code)) {
  121. if (!evc->evc_cond_state) {
  122. SMT_PANIC(smc,SMT_E0128, SMT_E0128_MSG) ;
  123. }
  124. evc->evc_multiple = &fail_safe ;
  125. }
  126. else {
  127. if (!evc->evc_multiple) {
  128. SMT_PANIC(smc,SMT_E0129, SMT_E0129_MSG) ;
  129. }
  130. evc->evc_cond_state = &fail_safe ;
  131. }
  132. }
  133. #endif
  134. smc->srf.TSR = smt_get_time() ;
  135. smc->srf.sr_state = SR0_WAIT ;
  136. }
  137. static struct s_srf_evc *smt_get_evc(struct s_smc *smc, int code, int index)
  138. {
  139. int i ;
  140. struct s_srf_evc *evc ;
  141. for (i = 0, evc = smc->evcs ; (unsigned) i < MAX_EVCS ; i++, evc++) {
  142. if (evc->evc_code == code && evc->evc_index == index)
  143. return evc;
  144. }
  145. return NULL;
  146. }
  147. #define THRESHOLD_2 (2*TICKS_PER_SECOND)
  148. #define THRESHOLD_32 (32*TICKS_PER_SECOND)
  149. #ifdef DEBUG
  150. static const char * const srf_names[] = {
  151. "None","MACPathChangeEvent", "MACNeighborChangeEvent",
  152. "PORTPathChangeEvent", "PORTUndesiredConnectionAttemptEvent",
  153. "SMTPeerWrapCondition", "SMTHoldCondition",
  154. "MACFrameErrorCondition", "MACDuplicateAddressCondition",
  155. "MACNotCopiedCondition", "PORTEBErrorCondition",
  156. "PORTLerCondition"
  157. } ;
  158. #endif
  159. void smt_srf_event(struct s_smc *smc, int code, int index, int cond)
  160. {
  161. struct s_srf_evc *evc ;
  162. int cond_asserted = 0 ;
  163. int cond_deasserted = 0 ;
  164. int event_occurred = 0 ;
  165. int tsr ;
  166. int T_Limit = 2*TICKS_PER_SECOND ;
  167. if (code == SMT_COND_MAC_DUP_ADDR && cond) {
  168. RS_SET(smc,RS_DUPADDR) ;
  169. }
  170. if (code) {
  171. DB_SMT("SRF: %s index %d\n",srf_names[code],index) ;
  172. if (!(evc = smt_get_evc(smc,code,index))) {
  173. DB_SMT("SRF : smt_get_evc() failed\n",0,0) ;
  174. return ;
  175. }
  176. /*
  177. * ignore condition if no change
  178. */
  179. if (SMT_IS_CONDITION(code)) {
  180. if (*evc->evc_cond_state == cond)
  181. return ;
  182. }
  183. /*
  184. * set transition time stamp
  185. */
  186. smt_set_timestamp(smc,smc->mib.fddiSMTTransitionTimeStamp) ;
  187. if (SMT_IS_CONDITION(code)) {
  188. DB_SMT("SRF: condition is %s\n",cond ? "ON":"OFF",0) ;
  189. if (cond) {
  190. *evc->evc_cond_state = TRUE ;
  191. evc->evc_rep_required = TRUE ;
  192. smc->srf.any_report = TRUE ;
  193. cond_asserted = TRUE ;
  194. }
  195. else {
  196. *evc->evc_cond_state = FALSE ;
  197. cond_deasserted = TRUE ;
  198. }
  199. }
  200. else {
  201. if (evc->evc_rep_required) {
  202. *evc->evc_multiple = TRUE ;
  203. }
  204. else {
  205. evc->evc_rep_required = TRUE ;
  206. *evc->evc_multiple = FALSE ;
  207. }
  208. smc->srf.any_report = TRUE ;
  209. event_occurred = TRUE ;
  210. }
  211. #ifdef FDDI_MIB
  212. snmp_srf_event(smc,evc) ;
  213. #endif /* FDDI_MIB */
  214. }
  215. tsr = smt_get_time() - smc->srf.TSR ;
  216. switch (smc->srf.sr_state) {
  217. case SR0_WAIT :
  218. /* SR01a */
  219. if (cond_asserted && tsr < T_Limit) {
  220. smc->srf.SRThreshold = THRESHOLD_2 ;
  221. smc->srf.sr_state = SR1_HOLDOFF ;
  222. break ;
  223. }
  224. /* SR01b */
  225. if (cond_deasserted && tsr < T_Limit) {
  226. smc->srf.sr_state = SR1_HOLDOFF ;
  227. break ;
  228. }
  229. /* SR01c */
  230. if (event_occurred && tsr < T_Limit) {
  231. smc->srf.sr_state = SR1_HOLDOFF ;
  232. break ;
  233. }
  234. /* SR00b */
  235. if (cond_asserted && tsr >= T_Limit) {
  236. smc->srf.SRThreshold = THRESHOLD_2 ;
  237. smc->srf.TSR = smt_get_time() ;
  238. smt_send_srf(smc) ;
  239. break ;
  240. }
  241. /* SR00c */
  242. if (cond_deasserted && tsr >= T_Limit) {
  243. smc->srf.TSR = smt_get_time() ;
  244. smt_send_srf(smc) ;
  245. break ;
  246. }
  247. /* SR00d */
  248. if (event_occurred && tsr >= T_Limit) {
  249. smc->srf.TSR = smt_get_time() ;
  250. smt_send_srf(smc) ;
  251. break ;
  252. }
  253. /* SR00e */
  254. if (smc->srf.any_report && (u_long) tsr >=
  255. smc->srf.SRThreshold) {
  256. smc->srf.SRThreshold *= 2 ;
  257. if (smc->srf.SRThreshold > THRESHOLD_32)
  258. smc->srf.SRThreshold = THRESHOLD_32 ;
  259. smc->srf.TSR = smt_get_time() ;
  260. smt_send_srf(smc) ;
  261. break ;
  262. }
  263. /* SR02 */
  264. if (!smc->mib.fddiSMTStatRptPolicy) {
  265. smc->srf.sr_state = SR2_DISABLED ;
  266. break ;
  267. }
  268. break ;
  269. case SR1_HOLDOFF :
  270. /* SR10b */
  271. if (tsr >= T_Limit) {
  272. smc->srf.sr_state = SR0_WAIT ;
  273. smc->srf.TSR = smt_get_time() ;
  274. smt_send_srf(smc) ;
  275. break ;
  276. }
  277. /* SR11a */
  278. if (cond_asserted) {
  279. smc->srf.SRThreshold = THRESHOLD_2 ;
  280. }
  281. /* SR11b */
  282. /* SR11c */
  283. /* handled above */
  284. /* SR12 */
  285. if (!smc->mib.fddiSMTStatRptPolicy) {
  286. smc->srf.sr_state = SR2_DISABLED ;
  287. break ;
  288. }
  289. break ;
  290. case SR2_DISABLED :
  291. if (smc->mib.fddiSMTStatRptPolicy) {
  292. smc->srf.sr_state = SR0_WAIT ;
  293. smc->srf.TSR = smt_get_time() ;
  294. smc->srf.SRThreshold = THRESHOLD_2 ;
  295. clear_all_rep(smc) ;
  296. break ;
  297. }
  298. break ;
  299. }
  300. }
  301. static void clear_all_rep(struct s_smc *smc)
  302. {
  303. struct s_srf_evc *evc ;
  304. int i ;
  305. for (i = 0, evc = smc->evcs ; (unsigned) i < MAX_EVCS ; i++, evc++) {
  306. evc->evc_rep_required = FALSE ;
  307. if (SMT_IS_CONDITION(evc->evc_code))
  308. *evc->evc_cond_state = FALSE ;
  309. }
  310. smc->srf.any_report = FALSE ;
  311. }
  312. static void clear_reported(struct s_smc *smc)
  313. {
  314. struct s_srf_evc *evc ;
  315. int i ;
  316. smc->srf.any_report = FALSE ;
  317. for (i = 0, evc = smc->evcs ; (unsigned) i < MAX_EVCS ; i++, evc++) {
  318. if (SMT_IS_CONDITION(evc->evc_code)) {
  319. if (*evc->evc_cond_state == FALSE)
  320. evc->evc_rep_required = FALSE ;
  321. else
  322. smc->srf.any_report = TRUE ;
  323. }
  324. else {
  325. evc->evc_rep_required = FALSE ;
  326. *evc->evc_multiple = FALSE ;
  327. }
  328. }
  329. }
  330. /*
  331. * build and send SMT SRF frame
  332. */
  333. static void smt_send_srf(struct s_smc *smc)
  334. {
  335. struct smt_header *smt ;
  336. struct s_srf_evc *evc ;
  337. SK_LOC_DECL(struct s_pcon,pcon) ;
  338. SMbuf *mb ;
  339. int i ;
  340. static const struct fddi_addr SMT_SRF_DA = {
  341. { 0x80, 0x01, 0x43, 0x00, 0x80, 0x08 }
  342. } ;
  343. /*
  344. * build SMT header
  345. */
  346. if (!smc->r.sm_ma_avail)
  347. return ;
  348. if (!(mb = smt_build_frame(smc,SMT_SRF,SMT_ANNOUNCE,0)))
  349. return ;
  350. RS_SET(smc,RS_SOFTERROR) ;
  351. smt = smtod(mb, struct smt_header *) ;
  352. smt->smt_dest = SMT_SRF_DA ; /* DA == SRF multicast */
  353. /*
  354. * setup parameter status
  355. */
  356. pcon.pc_len = SMT_MAX_INFO_LEN ; /* max para length */
  357. pcon.pc_err = 0 ; /* no error */
  358. pcon.pc_badset = 0 ; /* no bad set count */
  359. pcon.pc_p = (void *) (smt + 1) ; /* paras start here */
  360. smt_add_para(smc,&pcon,(u_short) SMT_P1033,0,0) ;
  361. smt_add_para(smc,&pcon,(u_short) SMT_P1034,0,0) ;
  362. for (i = 0, evc = smc->evcs ; (unsigned) i < MAX_EVCS ; i++, evc++) {
  363. if (evc->evc_rep_required) {
  364. smt_add_para(smc,&pcon,evc->evc_para,
  365. (int)evc->evc_index,0) ;
  366. }
  367. }
  368. smt->smt_len = SMT_MAX_INFO_LEN - pcon.pc_len ;
  369. mb->sm_len = smt->smt_len + sizeof(struct smt_header) ;
  370. DB_SMT("SRF: sending SRF at %x, len %d\n",smt,mb->sm_len) ;
  371. DB_SMT("SRF: state SR%d Threshold %d\n",
  372. smc->srf.sr_state,smc->srf.SRThreshold/TICKS_PER_SECOND) ;
  373. #ifdef DEBUG
  374. dump_smt(smc,smt,"SRF Send") ;
  375. #endif
  376. smt_send_frame(smc,mb,FC_SMT_INFO,0) ;
  377. clear_reported(smc) ;
  378. }
  379. #endif /* no BOOT */
  380. #endif /* no SLIM_SMT */