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 */
70 * symbolic state names
72 static const char * const ecm_states
[] = {
73 "EC0_OUT","EC1_IN","EC2_TRACE","EC3_LEAVE","EC4_PATH_TEST",
74 "EC5_INSERT","EC6_CHECK","EC7_DEINSERT"
78 * symbolic event names
80 static const char * const ecm_events
[] = {
81 "NONE","EC_CONNECT","EC_DISCONNECT","EC_TRACE_PROP","EC_PATH_TEST",
82 "EC_TIMEOUT_TD","EC_TIMEOUT_TMAX",
83 "EC_TIMEOUT_IMAX","EC_TIMEOUT_INMAX","EC_TEST_DONE"
87 * all Globals are defined in smc.h
92 * function declarations
95 static void ecm_fsm(struct s_smc
*smc
, int cmd
);
96 static void start_ecm_timer(struct s_smc
*smc
, u_long value
, int event
);
97 static void stop_ecm_timer(struct s_smc
*smc
);
98 static void prop_actions(struct s_smc
*smc
);
101 init ECM state machine
102 clear all ECM vars and flags
104 void ecm_init(struct s_smc
*smc
)
106 smc
->e
.path_test
= PT_PASSED
;
107 smc
->e
.trace_prop
= 0 ;
109 smc
->mib
.fddiSMTECMState
= ACTIONS(EC0_OUT
) ;
110 smc
->e
.ecm_line_state
= FALSE
;
122 void ecm(struct s_smc
*smc
, int event
)
127 DB_ECM("ECM : state %s%s event %s",
128 smc
->mib
.fddiSMTECMState
& AFLAG
? "ACTIONS " : "",
129 ecm_states
[smc
->mib
.fddiSMTECMState
& ~AFLAG
],
131 state
= smc
->mib
.fddiSMTECMState
;
134 } while (state
!= smc
->mib
.fddiSMTECMState
) ;
135 ecm_state_change(smc
,(int)smc
->mib
.fddiSMTECMState
) ;
141 static void ecm_fsm(struct s_smc
*smc
, int cmd
)
143 int ls_a
; /* current line state PHY A */
144 int ls_b
; /* current line state PHY B */
148 smc
->mib
.fddiSMTBypassPresent
= sm_pm_bypass_present(smc
) ;
149 if (cmd
== EC_CONNECT
)
150 smc
->mib
.fddiSMTRemoteDisconnectFlag
= FALSE
;
152 /* For AIX event notification: */
153 /* Is a disconnect command remotely issued ? */
154 if (cmd
== EC_DISCONNECT
&&
155 smc
->mib
.fddiSMTRemoteDisconnectFlag
== TRUE
)
156 AIX_EVENT (smc
, (u_long
) CIO_HARD_FAIL
, (u_long
)
157 FDDI_REMOTE_DISCONNECT
, smt_get_event_word(smc
),
158 smt_get_error_word(smc
) );
160 /*jd 05-Aug-1999 Bug #10419 "Port Disconnect fails at Dup MAc Cond."*/
161 if (cmd
== EC_CONNECT
) {
162 smc
->e
.DisconnectFlag
= FALSE
;
164 else if (cmd
== EC_DISCONNECT
) {
165 smc
->e
.DisconnectFlag
= TRUE
;
168 switch(smc
->mib
.fddiSMTECMState
) {
169 case ACTIONS(EC0_OUT
) :
171 * We do not perform a path test
173 smc
->e
.path_test
= PT_PASSED
;
174 smc
->e
.ecm_line_state
= FALSE
;
175 stop_ecm_timer(smc
) ;
180 if (cmd
== EC_CONNECT
&& !smc
->mib
.fddiSMTBypassPresent
181 && smc
->e
.path_test
==PT_PASSED
) {
186 else if (cmd
== EC_CONNECT
&& (smc
->e
.path_test
==PT_PASSED
) &&
187 smc
->mib
.fddiSMTBypassPresent
&&
188 (smc
->s
.sas
== SMT_DAS
)) {
189 GO_STATE(EC5_INSERT
) ;
193 case ACTIONS(EC1_IN
) :
194 stop_ecm_timer(smc
) ;
195 smc
->e
.trace_prop
= 0 ;
196 sm_ma_control(smc
,MA_TREQ
) ;
197 for (p
= 0 ; p
< NUMPHYS
; p
++)
198 if (smc
->mib
.p
[p
].fddiPORTHardwarePresent
)
199 queue_event(smc
,EVENT_PCMA
+p
,PC_START
) ;
204 if (cmd
== EC_TRACE_PROP
) {
206 GO_STATE(EC2_TRACE
) ;
210 else if (cmd
== EC_DISCONNECT
) {
211 GO_STATE(EC3_LEAVE
) ;
215 case ACTIONS(EC2_TRACE
) :
216 start_ecm_timer(smc
,MIB2US(smc
->mib
.fddiSMTTrace_MaxExpiration
),
222 if (cmd
== EC_TRACE_PROP
) {
224 GO_STATE(EC2_TRACE
) ;
228 else if (cmd
== EC_DISCONNECT
) {
229 smc
->e
.path_test
= PT_EXITING
;
230 GO_STATE(EC3_LEAVE
) ;
234 else if (smc
->e
.path_test
== PT_PENDING
) {
235 GO_STATE(EC3_LEAVE
) ;
239 else if (cmd
== EC_TIMEOUT_TMAX
) {
240 /* Trace_Max is expired */
241 /* -> send AIX_EVENT */
242 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
,
243 (u_long
) FDDI_SMT_ERROR
, (u_long
)
244 FDDI_TRACE_MAX
, smt_get_error_word(smc
));
245 smc
->e
.path_test
= PT_PENDING
;
246 GO_STATE(EC3_LEAVE
) ;
250 case ACTIONS(EC3_LEAVE
) :
251 start_ecm_timer(smc
,smc
->s
.ecm_td_min
,EC_TIMEOUT_TD
) ;
252 for (p
= 0 ; p
< NUMPHYS
; p
++)
253 queue_event(smc
,EVENT_PCMA
+p
,PC_STOP
) ;
258 if (cmd
== EC_TIMEOUT_TD
&& !smc
->mib
.fddiSMTBypassPresent
&&
259 (smc
->e
.path_test
!= PT_PENDING
)) {
264 else if (cmd
== EC_TIMEOUT_TD
&&
265 (smc
->e
.path_test
== PT_PENDING
)) {
266 GO_STATE(EC4_PATH_TEST
) ;
270 else if (cmd
== EC_CONNECT
&& smc
->e
.path_test
== PT_PASSED
) {
275 else if (cmd
== EC_DISCONNECT
&&
276 smc
->e
.path_test
== PT_PENDING
) {
277 smc
->e
.path_test
= PT_EXITING
;
279 * stay in state - state will be left via timeout
283 else if (cmd
== EC_TIMEOUT_TD
&&
284 smc
->mib
.fddiSMTBypassPresent
&&
285 smc
->e
.path_test
!= PT_PENDING
) {
286 GO_STATE(EC7_DEINSERT
) ;
290 case ACTIONS(EC4_PATH_TEST
) :
291 stop_ecm_timer(smc
) ;
292 smc
->e
.path_test
= PT_TESTING
;
293 start_ecm_timer(smc
,smc
->s
.ecm_test_done
,EC_TEST_DONE
) ;
294 /* now perform path test ... just a simulation */
298 /* path test done delay */
299 if (cmd
== EC_TEST_DONE
)
300 smc
->e
.path_test
= PT_PASSED
;
302 if (smc
->e
.path_test
== PT_FAILED
)
303 RS_SET(smc
,RS_PATHTEST
) ;
306 if (smc
->e
.path_test
== PT_FAILED
&&
307 !smc
->mib
.fddiSMTBypassPresent
) {
312 else if (cmd
== EC_DISCONNECT
&&
313 !smc
->mib
.fddiSMTBypassPresent
) {
318 else if (smc
->e
.path_test
== PT_PASSED
) {
323 else if (smc
->e
.path_test
== PT_FAILED
&&
324 smc
->mib
.fddiSMTBypassPresent
) {
325 GO_STATE(EC7_DEINSERT
) ;
329 else if (cmd
== EC_DISCONNECT
&&
330 smc
->mib
.fddiSMTBypassPresent
) {
331 GO_STATE(EC7_DEINSERT
) ;
335 case ACTIONS(EC5_INSERT
) :
336 sm_pm_bypass_req(smc
,BP_INSERT
);
337 start_ecm_timer(smc
,smc
->s
.ecm_in_max
,EC_TIMEOUT_INMAX
) ;
342 if (cmd
== EC_TIMEOUT_INMAX
) {
343 GO_STATE(EC6_CHECK
) ;
347 else if (cmd
== EC_DISCONNECT
) {
348 GO_STATE(EC7_DEINSERT
) ;
352 case ACTIONS(EC6_CHECK
) :
354 * in EC6_CHECK, we *POLL* the line state !
355 * check whether both bypass switches have switched.
357 start_ecm_timer(smc
,smc
->s
.ecm_check_poll
,0) ;
358 smc
->e
.ecm_line_state
= TRUE
; /* flag to pcm: report Q/HLS */
359 (void) sm_pm_ls_latch(smc
,PA
,1) ; /* enable line state latch */
360 (void) sm_pm_ls_latch(smc
,PB
,1) ; /* enable line state latch */
364 ls_a
= sm_pm_get_ls(smc
,PA
) ;
365 ls_b
= sm_pm_get_ls(smc
,PB
) ;
368 if (((ls_a
== PC_QLS
) || (ls_a
== PC_HLS
)) &&
369 ((ls_b
== PC_QLS
) || (ls_b
== PC_HLS
)) ) {
370 smc
->e
.sb_flag
= FALSE
;
371 smc
->e
.ecm_line_state
= FALSE
;
376 else if (!smc
->e
.sb_flag
&&
377 (((ls_a
== PC_ILS
) && (ls_b
== PC_QLS
)) ||
378 ((ls_a
== PC_QLS
) && (ls_b
== PC_ILS
)))){
379 smc
->e
.sb_flag
= TRUE
;
380 DB_ECMN(1, "ECM : EC6_CHECK - stuck bypass");
381 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
382 FDDI_SMT_ERROR
, (u_long
) FDDI_BYPASS_STUCK
,
383 smt_get_error_word(smc
));
386 else if (cmd
== EC_DISCONNECT
) {
387 smc
->e
.ecm_line_state
= FALSE
;
388 GO_STATE(EC7_DEINSERT
) ;
395 start_ecm_timer(smc
,smc
->s
.ecm_check_poll
,0) ;
398 case ACTIONS(EC7_DEINSERT
) :
399 sm_pm_bypass_req(smc
,BP_DEINSERT
);
400 start_ecm_timer(smc
,smc
->s
.ecm_i_max
,EC_TIMEOUT_IMAX
) ;
405 if (cmd
== EC_TIMEOUT_IMAX
) {
410 else if (cmd
== EC_CONNECT
&& smc
->e
.path_test
== PT_PASSED
) {
411 GO_STATE(EC5_INSERT
) ;
416 SMT_PANIC(smc
,SMT_E0107
, SMT_E0107_MSG
) ;
423 * trace propagation actions for SAS & DAS
425 static void prop_actions(struct s_smc
*smc
)
430 RS_SET(smc
,RS_EVENT
) ;
431 switch (smc
->s
.sas
) {
433 port_in
= port_out
= pcm_get_s_port(smc
) ;
436 port_in
= cfm_get_mac_input(smc
) ; /* PA or PB */
437 port_out
= cfm_get_mac_output(smc
) ; /* PA or PB */
440 SMT_PANIC(smc
,SMT_E0108
, SMT_E0108_MSG
) ;
444 DB_ECM("ECM : prop_actions - trace_prop %lu", smc
->e
.trace_prop
);
445 DB_ECM("ECM : prop_actions - in %d out %d", port_in
, port_out
);
447 if (smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_MAC
)) {
448 /* trace initiatior */
449 DB_ECM("ECM : initiate TRACE on PHY %c", 'A' + port_in
- PA
);
450 queue_event(smc
,EVENT_PCM
+port_in
,PC_TRACE
) ;
452 else if ((smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_PHY(PA
))) &&
454 /* trace propagate upstream */
455 DB_ECM("ECM : propagate TRACE on PHY B");
456 queue_event(smc
,EVENT_PCMB
,PC_TRACE
) ;
458 else if ((smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_PHY(PB
))) &&
460 /* trace propagate upstream */
461 DB_ECM("ECM : propagate TRACE on PHY A");
462 queue_event(smc
,EVENT_PCMA
,PC_TRACE
) ;
465 /* signal trace termination */
466 DB_ECM("ECM : TRACE terminated");
467 smc
->e
.path_test
= PT_PENDING
;
469 smc
->e
.trace_prop
= 0 ;
473 * trace propagation actions for Concentrator
475 static void prop_actions(struct s_smc
*smc
)
481 RS_SET(smc
,RS_EVENT
) ;
482 while (smc
->e
.trace_prop
) {
483 DB_ECM("ECM : prop_actions - trace_prop %d",
486 if (smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_MAC
)) {
487 initiator
= ENTITY_MAC
;
488 smc
->e
.trace_prop
&= ~ENTITY_BIT(ENTITY_MAC
) ;
489 DB_ECM("ECM: MAC initiates trace");
492 for (p
= NUMPHYS
-1 ; p
>= 0 ; p
--) {
493 if (smc
->e
.trace_prop
&
494 ENTITY_BIT(ENTITY_PHY(p
)))
497 initiator
= ENTITY_PHY(p
) ;
498 smc
->e
.trace_prop
&= ~ENTITY_BIT(ENTITY_PHY(p
)) ;
500 upstream
= cem_get_upstream(smc
,initiator
) ;
502 if (upstream
== ENTITY_MAC
) {
503 /* signal trace termination */
504 DB_ECM("ECM : TRACE terminated");
505 smc
->e
.path_test
= PT_PENDING
;
508 /* trace propagate upstream */
509 DB_ECM("ECM : propagate TRACE on PHY %d", upstream
);
510 queue_event(smc
,EVENT_PCM
+upstream
,PC_TRACE
) ;
518 * SMT timer interface
521 static void start_ecm_timer(struct s_smc
*smc
, u_long value
, int event
)
523 smt_timer_start(smc
,&smc
->e
.ecm_timer
,value
,EV_TOKEN(EVENT_ECM
,event
));
527 * SMT timer interface
530 static void stop_ecm_timer(struct s_smc
*smc
)
532 if (smc
->e
.ecm_timer
.tm_active
)
533 smt_timer_stop(smc
,&smc
->e
.ecm_timer
) ;