srf.c 9.8 KB

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