1 /******************************************************************************
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 * See the file "skfddi.c" for further information.
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.
13 * The information in this file is provided "AS IS" without warranty.
15 ******************************************************************************/
19 Configuration Management
24 * Hardware independent state machine implemantation
25 * The following external SMT functions are referenced :
29 * The following external HW dependent functions are referenced :
32 * The following HW dependent events are required :
41 #include "h/smtstate.h"
44 static const char ID_sccs[] = "@(#)cfm.c 2.18 98/10/06 (C) SK " ;
51 #define GO_STATE(x) (smc->mib.fddiSMTCF_State = (x)|AFLAG)
52 #define ACTIONS_DONE() (smc->mib.fddiSMTCF_State &= ~AFLAG)
53 #define ACTIONS(x) (x|AFLAG)
57 * symbolic state names
59 static const char * const cfm_states[] = {
60 "SC0_ISOLATED","CF1","CF2","CF3","CF4",
61 "SC1_WRAP_A","SC2_WRAP_B","SC5_TRHU_B","SC7_WRAP_S",
62 "SC9_C_WRAP_A","SC10_C_WRAP_B","SC11_C_WRAP_S","SC4_THRU_A"
66 * symbolic event names
68 static const char * const cfm_events[] = {
69 "NONE","CF_LOOP_A","CF_LOOP_B","CF_JOIN_A","CF_JOIN_B"
74 * map from state to downstream port type
76 static const u_char cf_to_ptype[] = {
77 TNONE,TNONE,TNONE,TNONE,TNONE,
85 #define CEM_PST_DOWN 0
87 #define CEM_PST_HOLD 2
88 /* define portstate array only for A and B port */
89 /* Do this within the smc structure (use in multiple cards) */
92 * all Globals are defined in smc.h
97 * function declarations
99 static void cfm_fsm() ;
102 init CFM state machine
103 clear all CFM vars and flags
108 smc->mib.fddiSMTCF_State = ACTIONS(SC0_ISOLATED) ;
111 smc->y[PA].scrub = 0 ;
112 smc->y[PB].scrub = 0 ;
113 smc->y[PA].cem_pst = CEM_PST_DOWN ;
114 smc->y[PB].cem_pst = CEM_PST_DOWN ;
117 /* Some terms conditions used by the selection criteria */
118 #define THRU_ENABLED(smc) (smc->y[PA].pc_mode != PM_TREE && \
119 smc->y[PB].pc_mode != PM_TREE)
120 /* Selection criteria for the ports */
121 static void selection_criteria (smc,phy)
126 switch (phy->mib->fddiPORTMy_Type) {
128 if ( !THRU_ENABLED(smc) && smc->y[PB].cf_join ) {
129 phy->wc_flag = TRUE ;
131 phy->wc_flag = FALSE ;
136 /* take precedence over PA */
137 phy->wc_flag = FALSE ;
140 phy->wc_flag = FALSE ;
143 phy->wc_flag = FALSE ;
149 void all_selection_criteria (smc)
155 for ( p = 0,phy = smc->y ; p < NUMPHYS; p++, phy++ ) {
156 /* Do the selection criteria */
157 selection_criteria (smc,phy);
161 static void cem_priv_state (smc, event)
164 /* State machine for private PORT states: used to optimize dual homing */
166 int np; /* Number of the port */
169 /* Do this only in a DAS */
170 if (smc->s.sas != SMT_DAS )
173 np = event - CF_JOIN;
175 if (np != PA && np != PB) {
178 /* Change the port state according to the event (portnumber) */
179 if (smc->y[np].cf_join) {
180 smc->y[np].cem_pst = CEM_PST_UP ;
181 } else if (!smc->y[np].wc_flag) {
182 /* set the port to done only if it is not withheld */
183 smc->y[np].cem_pst = CEM_PST_DOWN ;
186 /* Don't set an hold port to down */
188 /* Check all ports of restart conditions */
189 for (i = 0 ; i < 2 ; i ++ ) {
190 /* Check all port for PORT is on hold and no withhold is done */
191 if ( smc->y[i].cem_pst == CEM_PST_HOLD && !smc->y[i].wc_flag ) {
192 smc->y[i].cem_pst = CEM_PST_DOWN;
193 queue_event(smc,(int)(EVENT_PCM+i),PC_START) ;
195 if ( smc->y[i].cem_pst == CEM_PST_UP && smc->y[i].wc_flag ) {
196 smc->y[i].cem_pst = CEM_PST_HOLD;
197 queue_event(smc,(int)(EVENT_PCM+i),PC_START) ;
199 if ( smc->y[i].cem_pst == CEM_PST_DOWN && smc->y[i].wc_flag ) {
201 * The port must be restarted when the wc_flag
202 * will be reset. So set the port on hold.
204 smc->y[i].cem_pst = CEM_PST_HOLD;
223 int state ; /* remember last state */
227 /* We will do the following: */
228 /* - compute the variable WC_Flag for every port (This is where */
229 /* we can extend the requested path checking !!) */
230 /* - do the old (SMT 6.2 like) state machine */
231 /* - do the resulting station states */
233 all_selection_criteria (smc);
235 /* We will check now whether a state transition is allowed or not */
236 /* - change the portstates */
237 cem_priv_state (smc, event);
239 oldstate = smc->mib.fddiSMTCF_State ;
241 DB_CFM("CFM : state %s%s",
242 (smc->mib.fddiSMTCF_State & AFLAG) ? "ACTIONS " : "",
243 cfm_states[smc->mib.fddiSMTCF_State & ~AFLAG]) ;
244 DB_CFM(" event %s\n",cfm_events[event],0) ;
245 state = smc->mib.fddiSMTCF_State ;
248 } while (state != smc->mib.fddiSMTCF_State) ;
252 * check peer wrap condition
255 if ( (smc->mib.fddiSMTCF_State == SC9_C_WRAP_A &&
256 smc->y[PA].pc_mode == PM_PEER) ||
257 (smc->mib.fddiSMTCF_State == SC10_C_WRAP_B &&
258 smc->y[PB].pc_mode == PM_PEER) ||
259 (smc->mib.fddiSMTCF_State == SC11_C_WRAP_S &&
260 smc->y[PS].pc_mode == PM_PEER &&
261 smc->y[PS].mib->fddiPORTNeighborType != TS ) ) {
264 if (cond != smc->mib.fddiSMTPeerWrapFlag)
265 smt_srf_event(smc,SMT_COND_SMT_PEER_WRAP,0,cond) ;
269 * Don't send ever MAC_PATH_CHANGE events. Our MAC is hard-wired
270 * to the primary path.
275 if (smc->mib.fddiSMTCF_State != oldstate) {
276 smt_srf_event(smc,SMT_EVENT_MAC_PATH_CHANGE,INDEX_MAC,0) ;
279 #endif /* no SLIM_SMT */
284 smc->mib.m[MAC0].fddiMACDownstreamPORTType =
285 cf_to_ptype[smc->mib.fddiSMTCF_State] ;
286 cfm_state_change(smc,(int)smc->mib.fddiSMTCF_State) ;
293 static void cfm_fsm(smc,cmd)
297 switch(smc->mib.fddiSMTCF_State) {
298 case ACTIONS(SC0_ISOLATED) :
299 smc->mib.p[PA].fddiPORTCurrentPath = MIB_PATH_ISOLATED ;
300 smc->mib.p[PB].fddiPORTCurrentPath = MIB_PATH_ISOLATED ;
301 smc->mib.p[PA].fddiPORTMACPlacement = 0 ;
302 smc->mib.p[PB].fddiPORTMACPlacement = 0 ;
303 smc->mib.fddiSMTStationStatus = MIB_SMT_STASTA_SEPA ;
304 config_mux(smc,MUX_ISOLATE) ; /* configure PHY Mux */
305 smc->r.rm_loop = FALSE ;
306 smc->r.rm_join = FALSE ;
307 queue_event(smc,EVENT_RMT,RM_JOIN) ;/* signal RMT */
308 /* Don't do the WC-Flag changing here */
310 DB_CFMN(1,"CFM : %s\n",cfm_states[smc->mib.fddiSMTCF_State],0) ;
314 /*SAS port can be PA or PB ! */
315 if (smc->s.sas && (smc->y[PA].cf_join || smc->y[PA].cf_loop ||
316 smc->y[PB].cf_join || smc->y[PB].cf_loop)) {
317 GO_STATE(SC11_C_WRAP_S) ;
321 if ((smc->y[PA].cem_pst == CEM_PST_UP && smc->y[PA].cf_join &&
322 !smc->y[PA].wc_flag) || smc->y[PA].cf_loop) {
323 GO_STATE(SC9_C_WRAP_A) ;
327 if ((smc->y[PB].cem_pst == CEM_PST_UP && smc->y[PB].cf_join &&
328 !smc->y[PB].wc_flag) || smc->y[PB].cf_loop) {
329 GO_STATE(SC10_C_WRAP_B) ;
333 case ACTIONS(SC9_C_WRAP_A) :
334 smc->mib.p[PA].fddiPORTCurrentPath = MIB_PATH_CONCATENATED ;
335 smc->mib.p[PB].fddiPORTCurrentPath = MIB_PATH_ISOLATED ;
336 smc->mib.p[PA].fddiPORTMACPlacement = INDEX_MAC ;
337 smc->mib.p[PB].fddiPORTMACPlacement = 0 ;
338 smc->mib.fddiSMTStationStatus = MIB_SMT_STASTA_CON ;
339 config_mux(smc,MUX_WRAPA) ; /* configure PHY mux */
340 if (smc->y[PA].cf_loop) {
341 smc->r.rm_join = FALSE ;
342 smc->r.rm_loop = TRUE ;
343 queue_event(smc,EVENT_RMT,RM_LOOP) ;/* signal RMT */
345 if (smc->y[PA].cf_join) {
346 smc->r.rm_loop = FALSE ;
347 smc->r.rm_join = TRUE ;
348 queue_event(smc,EVENT_RMT,RM_JOIN) ;/* signal RMT */
351 DB_CFMN(1,"CFM : %s\n",cfm_states[smc->mib.fddiSMTCF_State],0) ;
355 if ( (smc->y[PA].wc_flag || !smc->y[PA].cf_join) &&
356 !smc->y[PA].cf_loop ) {
357 GO_STATE(SC0_ISOLATED) ;
361 else if ( (smc->y[PB].cf_loop && smc->y[PA].cf_join &&
362 smc->y[PA].cem_pst == CEM_PST_UP) ||
363 ((smc->y[PB].cf_loop ||
364 (smc->y[PB].cf_join &&
365 smc->y[PB].cem_pst == CEM_PST_UP)) &&
366 (smc->y[PA].pc_mode == PM_TREE ||
367 smc->y[PB].pc_mode == PM_TREE))) {
368 smc->y[PA].scrub = TRUE ;
369 GO_STATE(SC10_C_WRAP_B) ;
373 else if (!smc->s.attach_s &&
374 smc->y[PA].cf_join &&
375 smc->y[PA].cem_pst == CEM_PST_UP &&
376 smc->y[PA].pc_mode == PM_PEER && smc->y[PB].cf_join &&
377 smc->y[PB].cem_pst == CEM_PST_UP &&
378 smc->y[PB].pc_mode == PM_PEER) {
379 smc->y[PA].scrub = TRUE ;
380 smc->y[PB].scrub = TRUE ;
381 GO_STATE(SC4_THRU_A) ;
385 else if ( smc->s.attach_s &&
386 smc->y[PA].cf_join &&
387 smc->y[PA].cem_pst == CEM_PST_UP &&
388 smc->y[PA].pc_mode == PM_PEER &&
389 smc->y[PB].cf_join &&
390 smc->y[PB].cem_pst == CEM_PST_UP &&
391 smc->y[PB].pc_mode == PM_PEER) {
392 smc->y[PA].scrub = TRUE ;
393 smc->y[PB].scrub = TRUE ;
394 GO_STATE(SC5_THRU_B) ;
398 case ACTIONS(SC10_C_WRAP_B) :
399 smc->mib.p[PA].fddiPORTCurrentPath = MIB_PATH_ISOLATED ;
400 smc->mib.p[PB].fddiPORTCurrentPath = MIB_PATH_CONCATENATED ;
401 smc->mib.p[PA].fddiPORTMACPlacement = 0 ;
402 smc->mib.p[PB].fddiPORTMACPlacement = INDEX_MAC ;
403 smc->mib.fddiSMTStationStatus = MIB_SMT_STASTA_CON ;
404 config_mux(smc,MUX_WRAPB) ; /* configure PHY mux */
405 if (smc->y[PB].cf_loop) {
406 smc->r.rm_join = FALSE ;
407 smc->r.rm_loop = TRUE ;
408 queue_event(smc,EVENT_RMT,RM_LOOP) ;/* signal RMT */
410 if (smc->y[PB].cf_join) {
411 smc->r.rm_loop = FALSE ;
412 smc->r.rm_join = TRUE ;
413 queue_event(smc,EVENT_RMT,RM_JOIN) ;/* signal RMT */
416 DB_CFMN(1,"CFM : %s\n",cfm_states[smc->mib.fddiSMTCF_State],0) ;
420 if ( !smc->y[PB].cf_join && !smc->y[PB].cf_loop ) {
421 GO_STATE(SC0_ISOLATED) ;
425 else if ( smc->y[PA].cf_loop && smc->y[PA].pc_mode == PM_PEER &&
426 smc->y[PB].cf_join && smc->y[PB].pc_mode == PM_PEER) {
427 smc->y[PB].scrub = TRUE ;
428 GO_STATE(SC9_C_WRAP_A) ;
432 else if (!smc->s.attach_s &&
433 smc->y[PA].cf_join && smc->y[PA].pc_mode == PM_PEER &&
434 smc->y[PB].cf_join && smc->y[PB].pc_mode == PM_PEER) {
435 smc->y[PA].scrub = TRUE ;
436 smc->y[PB].scrub = TRUE ;
437 GO_STATE(SC4_THRU_A) ;
441 else if ( smc->s.attach_s &&
442 smc->y[PA].cf_join && smc->y[PA].pc_mode == PM_PEER &&
443 smc->y[PB].cf_join && smc->y[PB].pc_mode == PM_PEER) {
444 smc->y[PA].scrub = TRUE ;
445 smc->y[PB].scrub = TRUE ;
446 GO_STATE(SC5_THRU_B) ;
450 case ACTIONS(SC4_THRU_A) :
451 smc->mib.p[PA].fddiPORTCurrentPath = MIB_PATH_THRU ;
452 smc->mib.p[PB].fddiPORTCurrentPath = MIB_PATH_THRU ;
453 smc->mib.p[PA].fddiPORTMACPlacement = 0 ;
454 smc->mib.p[PB].fddiPORTMACPlacement = INDEX_MAC ;
455 smc->mib.fddiSMTStationStatus = MIB_SMT_STASTA_THRU ;
456 config_mux(smc,MUX_THRUA) ; /* configure PHY mux */
457 smc->r.rm_loop = FALSE ;
458 smc->r.rm_join = TRUE ;
459 queue_event(smc,EVENT_RMT,RM_JOIN) ;/* signal RMT */
461 DB_CFMN(1,"CFM : %s\n",cfm_states[smc->mib.fddiSMTCF_State],0) ;
465 if (smc->y[PB].wc_flag || !smc->y[PB].cf_join) {
466 smc->y[PA].scrub = TRUE ;
467 GO_STATE(SC9_C_WRAP_A) ;
471 else if (!smc->y[PA].cf_join || smc->y[PA].wc_flag) {
472 smc->y[PB].scrub = TRUE ;
473 GO_STATE(SC10_C_WRAP_B) ;
477 else if (smc->s.attach_s) {
478 smc->y[PB].scrub = TRUE ;
479 GO_STATE(SC5_THRU_B) ;
483 case ACTIONS(SC5_THRU_B) :
484 smc->mib.p[PA].fddiPORTCurrentPath = MIB_PATH_THRU ;
485 smc->mib.p[PB].fddiPORTCurrentPath = MIB_PATH_THRU ;
486 smc->mib.p[PA].fddiPORTMACPlacement = INDEX_MAC ;
487 smc->mib.p[PB].fddiPORTMACPlacement = 0 ;
488 smc->mib.fddiSMTStationStatus = MIB_SMT_STASTA_THRU ;
489 config_mux(smc,MUX_THRUB) ; /* configure PHY mux */
490 smc->r.rm_loop = FALSE ;
491 smc->r.rm_join = TRUE ;
492 queue_event(smc,EVENT_RMT,RM_JOIN) ;/* signal RMT */
494 DB_CFMN(1,"CFM : %s\n",cfm_states[smc->mib.fddiSMTCF_State],0) ;
498 if (!smc->y[PB].cf_join || smc->y[PB].wc_flag) {
499 smc->y[PA].scrub = TRUE ;
500 GO_STATE(SC9_C_WRAP_A) ;
504 else if (!smc->y[PA].cf_join || smc->y[PA].wc_flag) {
505 smc->y[PB].scrub = TRUE ;
506 GO_STATE(SC10_C_WRAP_B) ;
510 else if (!smc->s.attach_s) {
511 smc->y[PA].scrub = TRUE ;
512 GO_STATE(SC4_THRU_A) ;
516 case ACTIONS(SC11_C_WRAP_S) :
517 smc->mib.p[PS].fddiPORTCurrentPath = MIB_PATH_CONCATENATED ;
518 smc->mib.p[PS].fddiPORTMACPlacement = INDEX_MAC ;
519 smc->mib.fddiSMTStationStatus = MIB_SMT_STASTA_CON ;
520 config_mux(smc,MUX_WRAPS) ; /* configure PHY mux */
521 if (smc->y[PA].cf_loop || smc->y[PB].cf_loop) {
522 smc->r.rm_join = FALSE ;
523 smc->r.rm_loop = TRUE ;
524 queue_event(smc,EVENT_RMT,RM_LOOP) ;/* signal RMT */
526 if (smc->y[PA].cf_join || smc->y[PB].cf_join) {
527 smc->r.rm_loop = FALSE ;
528 smc->r.rm_join = TRUE ;
529 queue_event(smc,EVENT_RMT,RM_JOIN) ;/* signal RMT */
532 DB_CFMN(1,"CFM : %s\n",cfm_states[smc->mib.fddiSMTCF_State],0) ;
536 if ( !smc->y[PA].cf_join && !smc->y[PA].cf_loop &&
537 !smc->y[PB].cf_join && !smc->y[PB].cf_loop) {
538 GO_STATE(SC0_ISOLATED) ;
543 SMT_PANIC(smc,SMT_E0106, SMT_E0106_MSG) ;
549 * get MAC's input Port
553 int cfm_get_mac_input(smc)
556 return((smc->mib.fddiSMTCF_State == SC10_C_WRAP_B ||
557 smc->mib.fddiSMTCF_State == SC5_THRU_B) ? PB : PA) ;
561 * get MAC's output Port
565 int cfm_get_mac_output(smc)
568 return((smc->mib.fddiSMTCF_State == SC10_C_WRAP_B ||
569 smc->mib.fddiSMTCF_State == SC4_THRU_A) ? PB : PA) ;
572 static char path_iso[] = {
573 0,0, 0,RES_PORT, 0,PA + INDEX_PORT, 0,PATH_ISO,
574 0,0, 0,RES_MAC, 0,INDEX_MAC, 0,PATH_ISO,
575 0,0, 0,RES_PORT, 0,PB + INDEX_PORT, 0,PATH_ISO
578 static char path_wrap_a[] = {
579 0,0, 0,RES_PORT, 0,PA + INDEX_PORT, 0,PATH_PRIM,
580 0,0, 0,RES_MAC, 0,INDEX_MAC, 0,PATH_PRIM,
581 0,0, 0,RES_PORT, 0,PB + INDEX_PORT, 0,PATH_ISO
584 static char path_wrap_b[] = {
585 0,0, 0,RES_PORT, 0,PB + INDEX_PORT, 0,PATH_PRIM,
586 0,0, 0,RES_MAC, 0,INDEX_MAC, 0,PATH_PRIM,
587 0,0, 0,RES_PORT, 0,PA + INDEX_PORT, 0,PATH_ISO
590 static char path_thru[] = {
591 0,0, 0,RES_PORT, 0,PA + INDEX_PORT, 0,PATH_PRIM,
592 0,0, 0,RES_MAC, 0,INDEX_MAC, 0,PATH_PRIM,
593 0,0, 0,RES_PORT, 0,PB + INDEX_PORT, 0,PATH_PRIM
596 static char path_wrap_s[] = {
597 0,0, 0,RES_PORT, 0,PS + INDEX_PORT, 0,PATH_PRIM,
598 0,0, 0,RES_MAC, 0,INDEX_MAC, 0,PATH_PRIM,
601 static char path_iso_s[] = {
602 0,0, 0,RES_PORT, 0,PS + INDEX_PORT, 0,PATH_ISO,
603 0,0, 0,RES_MAC, 0,INDEX_MAC, 0,PATH_ISO,
606 int cem_build_path(smc,to,path_index)
614 switch (smc->mib.fddiSMTCF_State) {
617 path = smc->s.sas ? path_iso_s : path_iso ;
618 len = smc->s.sas ? sizeof(path_iso_s) : sizeof(path_iso) ;
622 len = sizeof(path_wrap_a) ;
626 len = sizeof(path_wrap_b) ;
630 len = sizeof(path_thru) ;
634 len = sizeof(path_wrap_s) ;
637 memcpy(to,path,len) ;
639 LINT_USE(path_index);