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 Entity Coordination Management
20 Hardware independent state machine
24 * Hardware independent state machine implemantation
25 * The following external SMT functions are referenced :
31 * The following external HW dependent functions are referenced :
36 * The following HW dependent events are required :
46 #include "h/smtstate.h"
49 static const char ID_sccs[] = "@(#)ecm.c 2.7 99/08/05 (C) SK " ;
56 #define GO_STATE(x) (smc->mib.fddiSMTECMState = (x)|AFLAG)
57 #define ACTIONS_DONE() (smc->mib.fddiSMTECMState &= ~AFLAG)
58 #define ACTIONS(x) (x|AFLAG)
60 #define EC0_OUT 0 /* not inserted */
61 #define EC1_IN 1 /* inserted */
62 #define EC2_TRACE 2 /* tracing */
63 #define EC3_LEAVE 3 /* leaving the ring */
64 #define EC4_PATH_TEST 4 /* performing path test */
65 #define EC5_INSERT 5 /* bypass being turned on */
66 #define EC6_CHECK 6 /* checking bypass */
67 #define EC7_DEINSERT 7 /* bypass being turnde off */
71 * symbolic state names
73 static const char * const ecm_states[] = {
74 "EC0_OUT","EC1_IN","EC2_TRACE","EC3_LEAVE","EC4_PATH_TEST",
75 "EC5_INSERT","EC6_CHECK","EC7_DEINSERT"
79 * symbolic event names
81 static const char * const ecm_events[] = {
82 "NONE","EC_CONNECT","EC_DISCONNECT","EC_TRACE_PROP","EC_PATH_TEST",
83 "EC_TIMEOUT_TD","EC_TIMEOUT_TMAX",
84 "EC_TIMEOUT_IMAX","EC_TIMEOUT_INMAX","EC_TEST_DONE"
89 * all Globals are defined in smc.h
94 * function declarations
97 static void ecm_fsm() ;
98 static void start_ecm_timer() ;
99 static void stop_ecm_timer() ;
100 static void prop_actions() ;
103 init ECM state machine
104 clear all ECM vars and flags
109 smc->e.path_test = PT_PASSED ;
110 smc->e.trace_prop = 0 ;
112 smc->mib.fddiSMTECMState = ACTIONS(EC0_OUT) ;
113 smc->e.ecm_line_state = FALSE ;
132 DB_ECM("ECM : state %s%s",
133 (smc->mib.fddiSMTECMState & AFLAG) ? "ACTIONS " : "",
134 ecm_states[smc->mib.fddiSMTECMState & ~AFLAG]) ;
135 DB_ECM(" event %s\n",ecm_events[event],0) ;
136 state = smc->mib.fddiSMTECMState ;
139 } while (state != smc->mib.fddiSMTECMState) ;
140 ecm_state_change(smc,(int)smc->mib.fddiSMTECMState) ;
146 static void ecm_fsm(smc,cmd)
150 int ls_a ; /* current line state PHY A */
151 int ls_b ; /* current line state PHY B */
155 smc->mib.fddiSMTBypassPresent = sm_pm_bypass_present(smc) ;
156 if (cmd == EC_CONNECT)
157 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
159 /* For AIX event notification: */
160 /* Is a disconnect command remotely issued ? */
161 if (cmd == EC_DISCONNECT &&
162 smc->mib.fddiSMTRemoteDisconnectFlag == TRUE)
163 AIX_EVENT (smc, (u_long) CIO_HARD_FAIL, (u_long)
164 FDDI_REMOTE_DISCONNECT, smt_get_event_word(smc),
165 smt_get_error_word(smc) );
167 /*jd 05-Aug-1999 Bug #10419 "Port Disconnect fails at Dup MAc Cond."*/
168 if (cmd == EC_CONNECT) {
169 smc->e.DisconnectFlag = FALSE ;
171 else if (cmd == EC_DISCONNECT) {
172 smc->e.DisconnectFlag = TRUE ;
175 switch(smc->mib.fddiSMTECMState) {
176 case ACTIONS(EC0_OUT) :
178 * We do not perform a path test
180 smc->e.path_test = PT_PASSED ;
181 smc->e.ecm_line_state = FALSE ;
182 stop_ecm_timer(smc) ;
187 if (cmd == EC_CONNECT && !smc->mib.fddiSMTBypassPresent
188 && smc->e.path_test==PT_PASSED) {
193 else if (cmd == EC_CONNECT && (smc->e.path_test==PT_PASSED) &&
194 smc->mib.fddiSMTBypassPresent &&
195 (smc->s.sas == SMT_DAS)) {
196 GO_STATE(EC5_INSERT) ;
200 case ACTIONS(EC1_IN) :
201 stop_ecm_timer(smc) ;
202 smc->e.trace_prop = 0 ;
203 sm_ma_control(smc,MA_TREQ) ;
204 for (p = 0 ; p < NUMPHYS ; p++)
205 if (smc->mib.p[p].fddiPORTHardwarePresent)
206 queue_event(smc,EVENT_PCMA+p,PC_START) ;
211 if (cmd == EC_TRACE_PROP) {
213 GO_STATE(EC2_TRACE) ;
217 else if (cmd == EC_DISCONNECT) {
218 GO_STATE(EC3_LEAVE) ;
222 case ACTIONS(EC2_TRACE) :
223 start_ecm_timer(smc,MIB2US(smc->mib.fddiSMTTrace_MaxExpiration),
229 if (cmd == EC_TRACE_PROP) {
231 GO_STATE(EC2_TRACE) ;
235 else if (cmd == EC_DISCONNECT) {
236 smc->e.path_test = PT_EXITING ;
237 GO_STATE(EC3_LEAVE) ;
241 else if (smc->e.path_test == PT_PENDING) {
242 GO_STATE(EC3_LEAVE) ;
246 else if (cmd == EC_TIMEOUT_TMAX) {
247 /* Trace_Max is expired */
248 /* -> send AIX_EVENT */
249 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS,
250 (u_long) FDDI_SMT_ERROR, (u_long)
251 FDDI_TRACE_MAX, smt_get_error_word(smc));
252 smc->e.path_test = PT_PENDING ;
253 GO_STATE(EC3_LEAVE) ;
257 case ACTIONS(EC3_LEAVE) :
258 start_ecm_timer(smc,smc->s.ecm_td_min,EC_TIMEOUT_TD) ;
259 for (p = 0 ; p < NUMPHYS ; p++)
260 queue_event(smc,EVENT_PCMA+p,PC_STOP) ;
265 if (cmd == EC_TIMEOUT_TD && !smc->mib.fddiSMTBypassPresent &&
266 (smc->e.path_test != PT_PENDING)) {
271 else if (cmd == EC_TIMEOUT_TD &&
272 (smc->e.path_test == PT_PENDING)) {
273 GO_STATE(EC4_PATH_TEST) ;
277 else if (cmd == EC_CONNECT && smc->e.path_test == PT_PASSED) {
282 else if (cmd == EC_DISCONNECT &&
283 smc->e.path_test == PT_PENDING) {
284 smc->e.path_test = PT_EXITING ;
286 * stay in state - state will be left via timeout
290 else if (cmd == EC_TIMEOUT_TD &&
291 smc->mib.fddiSMTBypassPresent &&
292 smc->e.path_test != PT_PENDING) {
293 GO_STATE(EC7_DEINSERT) ;
297 case ACTIONS(EC4_PATH_TEST) :
298 stop_ecm_timer(smc) ;
299 smc->e.path_test = PT_TESTING ;
300 start_ecm_timer(smc,smc->s.ecm_test_done,EC_TEST_DONE) ;
301 /* now perform path test ... just a simulation */
305 /* path test done delay */
306 if (cmd == EC_TEST_DONE)
307 smc->e.path_test = PT_PASSED ;
309 if (smc->e.path_test == PT_FAILED)
310 RS_SET(smc,RS_PATHTEST) ;
313 if (smc->e.path_test == PT_FAILED &&
314 !smc->mib.fddiSMTBypassPresent) {
319 else if (cmd == EC_DISCONNECT &&
320 !smc->mib.fddiSMTBypassPresent) {
325 else if (smc->e.path_test == PT_PASSED) {
330 else if (smc->e.path_test == PT_FAILED &&
331 smc->mib.fddiSMTBypassPresent) {
332 GO_STATE(EC7_DEINSERT) ;
336 else if (cmd == EC_DISCONNECT &&
337 smc->mib.fddiSMTBypassPresent) {
338 GO_STATE(EC7_DEINSERT) ;
342 case ACTIONS(EC5_INSERT) :
343 sm_pm_bypass_req(smc,BP_INSERT);
344 start_ecm_timer(smc,smc->s.ecm_in_max,EC_TIMEOUT_INMAX) ;
349 if (cmd == EC_TIMEOUT_INMAX) {
350 GO_STATE(EC6_CHECK) ;
354 else if (cmd == EC_DISCONNECT) {
355 GO_STATE(EC7_DEINSERT) ;
359 case ACTIONS(EC6_CHECK) :
361 * in EC6_CHECK, we *POLL* the line state !
362 * check whether both bypass switches have switched.
364 start_ecm_timer(smc,smc->s.ecm_check_poll,0) ;
365 smc->e.ecm_line_state = TRUE ; /* flag to pcm: report Q/HLS */
366 (void) sm_pm_ls_latch(smc,PA,1) ; /* enable line state latch */
367 (void) sm_pm_ls_latch(smc,PB,1) ; /* enable line state latch */
371 ls_a = sm_pm_get_ls(smc,PA) ;
372 ls_b = sm_pm_get_ls(smc,PB) ;
375 if (((ls_a == PC_QLS) || (ls_a == PC_HLS)) &&
376 ((ls_b == PC_QLS) || (ls_b == PC_HLS)) ) {
377 smc->e.sb_flag = FALSE ;
378 smc->e.ecm_line_state = FALSE ;
383 else if (!smc->e.sb_flag &&
384 (((ls_a == PC_ILS) && (ls_b == PC_QLS)) ||
385 ((ls_a == PC_QLS) && (ls_b == PC_ILS)))){
386 smc->e.sb_flag = TRUE ;
387 DB_ECMN(1,"ECM : EC6_CHECK - stuck bypass\n",0,0) ;
388 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
389 FDDI_SMT_ERROR, (u_long) FDDI_BYPASS_STUCK,
390 smt_get_error_word(smc));
393 else if (cmd == EC_DISCONNECT) {
394 smc->e.ecm_line_state = FALSE ;
395 GO_STATE(EC7_DEINSERT) ;
402 start_ecm_timer(smc,smc->s.ecm_check_poll,0) ;
405 case ACTIONS(EC7_DEINSERT) :
406 sm_pm_bypass_req(smc,BP_DEINSERT);
407 start_ecm_timer(smc,smc->s.ecm_i_max,EC_TIMEOUT_IMAX) ;
412 if (cmd == EC_TIMEOUT_IMAX) {
417 else if (cmd == EC_CONNECT && smc->e.path_test == PT_PASSED) {
418 GO_STATE(EC5_INSERT) ;
423 SMT_PANIC(smc,SMT_E0107, SMT_E0107_MSG) ;
430 * trace propagation actions for SAS & DAS
432 static void prop_actions(smc)
438 RS_SET(smc,RS_EVENT) ;
439 switch (smc->s.sas) {
441 port_in = port_out = pcm_get_s_port(smc) ;
444 port_in = cfm_get_mac_input(smc) ; /* PA or PB */
445 port_out = cfm_get_mac_output(smc) ; /* PA or PB */
448 SMT_PANIC(smc,SMT_E0108, SMT_E0108_MSG) ;
452 DB_ECM("ECM : prop_actions - trace_prop %d\n", smc->e.trace_prop,0) ;
453 DB_ECM("ECM : prop_actions - in %d out %d\n", port_in,port_out) ;
455 if (smc->e.trace_prop & ENTITY_BIT(ENTITY_MAC)) {
456 /* trace initiatior */
457 DB_ECM("ECM : initiate TRACE on PHY %c\n",'A'+port_in-PA,0) ;
458 queue_event(smc,EVENT_PCM+port_in,PC_TRACE) ;
460 else if ((smc->e.trace_prop & ENTITY_BIT(ENTITY_PHY(PA))) &&
462 /* trace propagate upstream */
463 DB_ECM("ECM : propagate TRACE on PHY B\n",0,0) ;
464 queue_event(smc,EVENT_PCMB,PC_TRACE) ;
466 else if ((smc->e.trace_prop & ENTITY_BIT(ENTITY_PHY(PB))) &&
468 /* trace propagate upstream */
469 DB_ECM("ECM : propagate TRACE on PHY A\n",0,0) ;
470 queue_event(smc,EVENT_PCMA,PC_TRACE) ;
473 /* signal trace termination */
474 DB_ECM("ECM : TRACE terminated\n",0,0) ;
475 smc->e.path_test = PT_PENDING ;
477 smc->e.trace_prop = 0 ;
481 * trace propagation actions for Concentrator
483 static void prop_actions(smc)
490 RS_SET(smc,RS_EVENT) ;
491 while (smc->e.trace_prop) {
492 DB_ECM("ECM : prop_actions - trace_prop %d\n",
493 smc->e.trace_prop,0) ;
495 if (smc->e.trace_prop & ENTITY_BIT(ENTITY_MAC)) {
496 initiator = ENTITY_MAC ;
497 smc->e.trace_prop &= ~ENTITY_BIT(ENTITY_MAC) ;
498 DB_ECM("ECM: MAC initiates trace\n",0,0) ;
501 for (p = NUMPHYS-1 ; p >= 0 ; p--) {
502 if (smc->e.trace_prop &
503 ENTITY_BIT(ENTITY_PHY(p)))
506 initiator = ENTITY_PHY(p) ;
507 smc->e.trace_prop &= ~ENTITY_BIT(ENTITY_PHY(p)) ;
509 upstream = cem_get_upstream(smc,initiator) ;
511 if (upstream == ENTITY_MAC) {
512 /* signal trace termination */
513 DB_ECM("ECM : TRACE terminated\n",0,0) ;
514 smc->e.path_test = PT_PENDING ;
517 /* trace propagate upstream */
518 DB_ECM("ECM : propagate TRACE on PHY %d\n",upstream,0) ;
519 queue_event(smc,EVENT_PCM+upstream,PC_TRACE) ;
527 * SMT timer interface
530 static void start_ecm_timer(smc,value,event)
535 smt_timer_start(smc,&smc->e.ecm_timer,value,EV_TOKEN(EVENT_ECM,event));
539 * SMT timer interface
542 static void stop_ecm_timer(smc)
545 if (smc->e.ecm_timer.tm_active)
546 smt_timer_stop(smc,&smc->e.ecm_timer) ;