srf.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. unsigned 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 ; 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 int) (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 ; 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. unsigned int i ;
  140. struct s_srf_evc *evc ;
  141. for (i = 0, evc = smc->evcs ; 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. static const char * const srf_names[] = {
  150. "None","MACPathChangeEvent", "MACNeighborChangeEvent",
  151. "PORTPathChangeEvent", "PORTUndesiredConnectionAttemptEvent",
  152. "SMTPeerWrapCondition", "SMTHoldCondition",
  153. "MACFrameErrorCondition", "MACDuplicateAddressCondition",
  154. "MACNotCopiedCondition", "PORTEBErrorCondition",
  155. "PORTLerCondition"
  156. } ;
  157. void smt_srf_event(struct s_smc *smc, int code, int index, int cond)
  158. {
  159. struct s_srf_evc *evc ;
  160. int cond_asserted = 0 ;
  161. int cond_deasserted = 0 ;
  162. int event_occurred = 0 ;
  163. int tsr ;
  164. int T_Limit = 2*TICKS_PER_SECOND ;
  165. if (code == SMT_COND_MAC_DUP_ADDR && cond) {
  166. RS_SET(smc,RS_DUPADDR) ;
  167. }
  168. if (code) {
  169. DB_SMT("SRF: %s index %d", srf_names[code], index);
  170. if (!(evc = smt_get_evc(smc,code,index))) {
  171. DB_SMT("SRF : smt_get_evc() failed");
  172. return ;
  173. }
  174. /*
  175. * ignore condition if no change
  176. */
  177. if (SMT_IS_CONDITION(code)) {
  178. if (*evc->evc_cond_state == cond)
  179. return ;
  180. }
  181. /*
  182. * set transition time stamp
  183. */
  184. smt_set_timestamp(smc,smc->mib.fddiSMTTransitionTimeStamp) ;
  185. if (SMT_IS_CONDITION(code)) {
  186. DB_SMT("SRF: condition is %s", cond ? "ON" : "OFF");
  187. if (cond) {
  188. *evc->evc_cond_state = TRUE ;
  189. evc->evc_rep_required = TRUE ;
  190. smc->srf.any_report = TRUE ;
  191. cond_asserted = TRUE ;
  192. }
  193. else {
  194. *evc->evc_cond_state = FALSE ;
  195. cond_deasserted = TRUE ;
  196. }
  197. }
  198. else {
  199. if (evc->evc_rep_required) {
  200. *evc->evc_multiple = TRUE ;
  201. }
  202. else {
  203. evc->evc_rep_required = TRUE ;
  204. *evc->evc_multiple = FALSE ;
  205. }
  206. smc->srf.any_report = TRUE ;
  207. event_occurred = TRUE ;
  208. }
  209. #ifdef FDDI_MIB
  210. snmp_srf_event(smc,evc) ;
  211. #endif /* FDDI_MIB */
  212. }
  213. tsr = smt_get_time() - smc->srf.TSR ;
  214. switch (smc->srf.sr_state) {
  215. case SR0_WAIT :
  216. /* SR01a */
  217. if (cond_asserted && tsr < T_Limit) {
  218. smc->srf.SRThreshold = THRESHOLD_2 ;
  219. smc->srf.sr_state = SR1_HOLDOFF ;
  220. break ;
  221. }
  222. /* SR01b */
  223. if (cond_deasserted && tsr < T_Limit) {
  224. smc->srf.sr_state = SR1_HOLDOFF ;
  225. break ;
  226. }
  227. /* SR01c */
  228. if (event_occurred && tsr < T_Limit) {
  229. smc->srf.sr_state = SR1_HOLDOFF ;
  230. break ;
  231. }
  232. /* SR00b */
  233. if (cond_asserted && tsr >= T_Limit) {
  234. smc->srf.SRThreshold = THRESHOLD_2 ;
  235. smc->srf.TSR = smt_get_time() ;
  236. smt_send_srf(smc) ;
  237. break ;
  238. }
  239. /* SR00c */
  240. if (cond_deasserted && tsr >= T_Limit) {
  241. smc->srf.TSR = smt_get_time() ;
  242. smt_send_srf(smc) ;
  243. break ;
  244. }
  245. /* SR00d */
  246. if (event_occurred && tsr >= T_Limit) {
  247. smc->srf.TSR = smt_get_time() ;
  248. smt_send_srf(smc) ;
  249. break ;
  250. }
  251. /* SR00e */
  252. if (smc->srf.any_report && (u_long) tsr >=
  253. smc->srf.SRThreshold) {
  254. smc->srf.SRThreshold *= 2 ;
  255. if (smc->srf.SRThreshold > THRESHOLD_32)
  256. smc->srf.SRThreshold = THRESHOLD_32 ;
  257. smc->srf.TSR = smt_get_time() ;
  258. smt_send_srf(smc) ;
  259. break ;
  260. }
  261. /* SR02 */
  262. if (!smc->mib.fddiSMTStatRptPolicy) {
  263. smc->srf.sr_state = SR2_DISABLED ;
  264. break ;
  265. }
  266. break ;
  267. case SR1_HOLDOFF :
  268. /* SR10b */
  269. if (tsr >= T_Limit) {
  270. smc->srf.sr_state = SR0_WAIT ;
  271. smc->srf.TSR = smt_get_time() ;
  272. smt_send_srf(smc) ;
  273. break ;
  274. }
  275. /* SR11a */
  276. if (cond_asserted) {
  277. smc->srf.SRThreshold = THRESHOLD_2 ;
  278. }
  279. /* SR11b */
  280. /* SR11c */
  281. /* handled above */
  282. /* SR12 */
  283. if (!smc->mib.fddiSMTStatRptPolicy) {
  284. smc->srf.sr_state = SR2_DISABLED ;
  285. break ;
  286. }
  287. break ;
  288. case SR2_DISABLED :
  289. if (smc->mib.fddiSMTStatRptPolicy) {
  290. smc->srf.sr_state = SR0_WAIT ;
  291. smc->srf.TSR = smt_get_time() ;
  292. smc->srf.SRThreshold = THRESHOLD_2 ;
  293. clear_all_rep(smc) ;
  294. break ;
  295. }
  296. break ;
  297. }
  298. }
  299. static void clear_all_rep(struct s_smc *smc)
  300. {
  301. struct s_srf_evc *evc ;
  302. unsigned int i ;
  303. for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
  304. evc->evc_rep_required = FALSE ;
  305. if (SMT_IS_CONDITION(evc->evc_code))
  306. *evc->evc_cond_state = FALSE ;
  307. }
  308. smc->srf.any_report = FALSE ;
  309. }
  310. static void clear_reported(struct s_smc *smc)
  311. {
  312. struct s_srf_evc *evc ;
  313. unsigned int i ;
  314. smc->srf.any_report = FALSE ;
  315. for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
  316. if (SMT_IS_CONDITION(evc->evc_code)) {
  317. if (*evc->evc_cond_state == FALSE)
  318. evc->evc_rep_required = FALSE ;
  319. else
  320. smc->srf.any_report = TRUE ;
  321. }
  322. else {
  323. evc->evc_rep_required = FALSE ;
  324. *evc->evc_multiple = FALSE ;
  325. }
  326. }
  327. }
  328. /*
  329. * build and send SMT SRF frame
  330. */
  331. static void smt_send_srf(struct s_smc *smc)
  332. {
  333. struct smt_header *smt ;
  334. struct s_srf_evc *evc ;
  335. SK_LOC_DECL(struct s_pcon,pcon) ;
  336. SMbuf *mb ;
  337. unsigned int i ;
  338. static const struct fddi_addr SMT_SRF_DA = {
  339. { 0x80, 0x01, 0x43, 0x00, 0x80, 0x08 }
  340. } ;
  341. /*
  342. * build SMT header
  343. */
  344. if (!smc->r.sm_ma_avail)
  345. return ;
  346. if (!(mb = smt_build_frame(smc,SMT_SRF,SMT_ANNOUNCE,0)))
  347. return ;
  348. RS_SET(smc,RS_SOFTERROR) ;
  349. smt = smtod(mb, struct smt_header *) ;
  350. smt->smt_dest = SMT_SRF_DA ; /* DA == SRF multicast */
  351. /*
  352. * setup parameter status
  353. */
  354. pcon.pc_len = SMT_MAX_INFO_LEN ; /* max para length */
  355. pcon.pc_err = 0 ; /* no error */
  356. pcon.pc_badset = 0 ; /* no bad set count */
  357. pcon.pc_p = (void *) (smt + 1) ; /* paras start here */
  358. smt_add_para(smc,&pcon,(u_short) SMT_P1033,0,0) ;
  359. smt_add_para(smc,&pcon,(u_short) SMT_P1034,0,0) ;
  360. for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
  361. if (evc->evc_rep_required) {
  362. smt_add_para(smc,&pcon,evc->evc_para,
  363. (int)evc->evc_index,0) ;
  364. }
  365. }
  366. smt->smt_len = SMT_MAX_INFO_LEN - pcon.pc_len ;
  367. mb->sm_len = smt->smt_len + sizeof(struct smt_header) ;
  368. DB_SMT("SRF: sending SRF at %p, len %d", smt, mb->sm_len);
  369. DB_SMT("SRF: state SR%d Threshold %lu",
  370. smc->srf.sr_state, smc->srf.SRThreshold / TICKS_PER_SECOND);
  371. #ifdef DEBUG
  372. dump_smt(smc,smt,"SRF Send") ;
  373. #endif
  374. smt_send_frame(smc,mb,FC_SMT_INFO,0) ;
  375. clear_reported(smc) ;
  376. }
  377. #endif /* no BOOT */
  378. #endif /* no SLIM_SMT */