1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
7 * See the file "skfddi.c" for further information.
9 * The information in this file is provided "AS IS" without warranty.
11 ******************************************************************************/
15 Entity Coordination Management
16 Hardware independent state machine
20 * Hardware independent state machine implemantation
21 * The following external SMT functions are referenced :
27 * The following external HW dependent functions are referenced :
31 * The following HW dependent events are required :
41 #include "h/smtstate.h"
44 static const char ID_sccs
[] = "@(#)ecm.c 2.7 99/08/05 (C) SK " ;
51 #define GO_STATE(x) (smc->mib.fddiSMTECMState = (x)|AFLAG)
52 #define ACTIONS_DONE() (smc->mib.fddiSMTECMState &= ~AFLAG)
53 #define ACTIONS(x) (x|AFLAG)
55 #define EC0_OUT 0 /* not inserted */
56 #define EC1_IN 1 /* inserted */
57 #define EC2_TRACE 2 /* tracing */
58 #define EC3_LEAVE 3 /* leaving the ring */
59 #define EC4_PATH_TEST 4 /* performing path test */
60 #define EC5_INSERT 5 /* bypass being turned on */
61 #define EC6_CHECK 6 /* checking bypass */
62 #define EC7_DEINSERT 7 /* bypass being turnde off */
65 * symbolic state names
67 static const char * const ecm_states
[] = {
68 "EC0_OUT","EC1_IN","EC2_TRACE","EC3_LEAVE","EC4_PATH_TEST",
69 "EC5_INSERT","EC6_CHECK","EC7_DEINSERT"
73 * symbolic event names
75 static const char * const ecm_events
[] = {
76 "NONE","EC_CONNECT","EC_DISCONNECT","EC_TRACE_PROP","EC_PATH_TEST",
77 "EC_TIMEOUT_TD","EC_TIMEOUT_TMAX",
78 "EC_TIMEOUT_IMAX","EC_TIMEOUT_INMAX","EC_TEST_DONE"
82 * all Globals are defined in smc.h
87 * function declarations
90 static void ecm_fsm(struct s_smc
*smc
, int cmd
);
91 static void start_ecm_timer(struct s_smc
*smc
, u_long value
, int event
);
92 static void stop_ecm_timer(struct s_smc
*smc
);
93 static void prop_actions(struct s_smc
*smc
);
96 init ECM state machine
97 clear all ECM vars and flags
99 void ecm_init(struct s_smc
*smc
)
101 smc
->e
.path_test
= PT_PASSED
;
102 smc
->e
.trace_prop
= 0 ;
104 smc
->mib
.fddiSMTECMState
= ACTIONS(EC0_OUT
) ;
105 smc
->e
.ecm_line_state
= FALSE
;
117 void ecm(struct s_smc
*smc
, int event
)
122 DB_ECM("ECM : state %s%s event %s",
123 smc
->mib
.fddiSMTECMState
& AFLAG
? "ACTIONS " : "",
124 ecm_states
[smc
->mib
.fddiSMTECMState
& ~AFLAG
],
126 state
= smc
->mib
.fddiSMTECMState
;
129 } while (state
!= smc
->mib
.fddiSMTECMState
) ;
130 ecm_state_change(smc
,(int)smc
->mib
.fddiSMTECMState
) ;
136 static void ecm_fsm(struct s_smc
*smc
, int cmd
)
138 int ls_a
; /* current line state PHY A */
139 int ls_b
; /* current line state PHY B */
143 smc
->mib
.fddiSMTBypassPresent
= sm_pm_bypass_present(smc
) ;
144 if (cmd
== EC_CONNECT
)
145 smc
->mib
.fddiSMTRemoteDisconnectFlag
= FALSE
;
147 /* For AIX event notification: */
148 /* Is a disconnect command remotely issued ? */
149 if (cmd
== EC_DISCONNECT
&&
150 smc
->mib
.fddiSMTRemoteDisconnectFlag
== TRUE
)
151 AIX_EVENT (smc
, (u_long
) CIO_HARD_FAIL
, (u_long
)
152 FDDI_REMOTE_DISCONNECT
, smt_get_event_word(smc
),
153 smt_get_error_word(smc
) );
155 /*jd 05-Aug-1999 Bug #10419 "Port Disconnect fails at Dup MAc Cond."*/
156 if (cmd
== EC_CONNECT
) {
157 smc
->e
.DisconnectFlag
= FALSE
;
159 else if (cmd
== EC_DISCONNECT
) {
160 smc
->e
.DisconnectFlag
= TRUE
;
163 switch(smc
->mib
.fddiSMTECMState
) {
164 case ACTIONS(EC0_OUT
) :
166 * We do not perform a path test
168 smc
->e
.path_test
= PT_PASSED
;
169 smc
->e
.ecm_line_state
= FALSE
;
170 stop_ecm_timer(smc
) ;
175 if (cmd
== EC_CONNECT
&& !smc
->mib
.fddiSMTBypassPresent
176 && smc
->e
.path_test
==PT_PASSED
) {
181 else if (cmd
== EC_CONNECT
&& (smc
->e
.path_test
==PT_PASSED
) &&
182 smc
->mib
.fddiSMTBypassPresent
&&
183 (smc
->s
.sas
== SMT_DAS
)) {
184 GO_STATE(EC5_INSERT
) ;
188 case ACTIONS(EC1_IN
) :
189 stop_ecm_timer(smc
) ;
190 smc
->e
.trace_prop
= 0 ;
191 sm_ma_control(smc
,MA_TREQ
) ;
192 for (p
= 0 ; p
< NUMPHYS
; p
++)
193 if (smc
->mib
.p
[p
].fddiPORTHardwarePresent
)
194 queue_event(smc
,EVENT_PCMA
+p
,PC_START
) ;
199 if (cmd
== EC_TRACE_PROP
) {
201 GO_STATE(EC2_TRACE
) ;
205 else if (cmd
== EC_DISCONNECT
) {
206 GO_STATE(EC3_LEAVE
) ;
210 case ACTIONS(EC2_TRACE
) :
211 start_ecm_timer(smc
,MIB2US(smc
->mib
.fddiSMTTrace_MaxExpiration
),
217 if (cmd
== EC_TRACE_PROP
) {
219 GO_STATE(EC2_TRACE
) ;
223 else if (cmd
== EC_DISCONNECT
) {
224 smc
->e
.path_test
= PT_EXITING
;
225 GO_STATE(EC3_LEAVE
) ;
229 else if (smc
->e
.path_test
== PT_PENDING
) {
230 GO_STATE(EC3_LEAVE
) ;
234 else if (cmd
== EC_TIMEOUT_TMAX
) {
235 /* Trace_Max is expired */
236 /* -> send AIX_EVENT */
237 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
,
238 (u_long
) FDDI_SMT_ERROR
, (u_long
)
239 FDDI_TRACE_MAX
, smt_get_error_word(smc
));
240 smc
->e
.path_test
= PT_PENDING
;
241 GO_STATE(EC3_LEAVE
) ;
245 case ACTIONS(EC3_LEAVE
) :
246 start_ecm_timer(smc
,smc
->s
.ecm_td_min
,EC_TIMEOUT_TD
) ;
247 for (p
= 0 ; p
< NUMPHYS
; p
++)
248 queue_event(smc
,EVENT_PCMA
+p
,PC_STOP
) ;
253 if (cmd
== EC_TIMEOUT_TD
&& !smc
->mib
.fddiSMTBypassPresent
&&
254 (smc
->e
.path_test
!= PT_PENDING
)) {
259 else if (cmd
== EC_TIMEOUT_TD
&&
260 (smc
->e
.path_test
== PT_PENDING
)) {
261 GO_STATE(EC4_PATH_TEST
) ;
265 else if (cmd
== EC_CONNECT
&& smc
->e
.path_test
== PT_PASSED
) {
270 else if (cmd
== EC_DISCONNECT
&&
271 smc
->e
.path_test
== PT_PENDING
) {
272 smc
->e
.path_test
= PT_EXITING
;
274 * stay in state - state will be left via timeout
278 else if (cmd
== EC_TIMEOUT_TD
&&
279 smc
->mib
.fddiSMTBypassPresent
&&
280 smc
->e
.path_test
!= PT_PENDING
) {
281 GO_STATE(EC7_DEINSERT
) ;
285 case ACTIONS(EC4_PATH_TEST
) :
286 stop_ecm_timer(smc
) ;
287 smc
->e
.path_test
= PT_TESTING
;
288 start_ecm_timer(smc
,smc
->s
.ecm_test_done
,EC_TEST_DONE
) ;
289 /* now perform path test ... just a simulation */
293 /* path test done delay */
294 if (cmd
== EC_TEST_DONE
)
295 smc
->e
.path_test
= PT_PASSED
;
297 if (smc
->e
.path_test
== PT_FAILED
)
298 RS_SET(smc
,RS_PATHTEST
) ;
301 if (smc
->e
.path_test
== PT_FAILED
&&
302 !smc
->mib
.fddiSMTBypassPresent
) {
307 else if (cmd
== EC_DISCONNECT
&&
308 !smc
->mib
.fddiSMTBypassPresent
) {
313 else if (smc
->e
.path_test
== PT_PASSED
) {
318 else if (smc
->e
.path_test
== PT_FAILED
&&
319 smc
->mib
.fddiSMTBypassPresent
) {
320 GO_STATE(EC7_DEINSERT
) ;
324 else if (cmd
== EC_DISCONNECT
&&
325 smc
->mib
.fddiSMTBypassPresent
) {
326 GO_STATE(EC7_DEINSERT
) ;
330 case ACTIONS(EC5_INSERT
) :
331 sm_pm_bypass_req(smc
,BP_INSERT
);
332 start_ecm_timer(smc
,smc
->s
.ecm_in_max
,EC_TIMEOUT_INMAX
) ;
337 if (cmd
== EC_TIMEOUT_INMAX
) {
338 GO_STATE(EC6_CHECK
) ;
342 else if (cmd
== EC_DISCONNECT
) {
343 GO_STATE(EC7_DEINSERT
) ;
347 case ACTIONS(EC6_CHECK
) :
349 * in EC6_CHECK, we *POLL* the line state !
350 * check whether both bypass switches have switched.
352 start_ecm_timer(smc
,smc
->s
.ecm_check_poll
,0) ;
353 smc
->e
.ecm_line_state
= TRUE
; /* flag to pcm: report Q/HLS */
357 ls_a
= sm_pm_get_ls(smc
,PA
) ;
358 ls_b
= sm_pm_get_ls(smc
,PB
) ;
361 if (((ls_a
== PC_QLS
) || (ls_a
== PC_HLS
)) &&
362 ((ls_b
== PC_QLS
) || (ls_b
== PC_HLS
)) ) {
363 smc
->e
.sb_flag
= FALSE
;
364 smc
->e
.ecm_line_state
= FALSE
;
369 else if (!smc
->e
.sb_flag
&&
370 (((ls_a
== PC_ILS
) && (ls_b
== PC_QLS
)) ||
371 ((ls_a
== PC_QLS
) && (ls_b
== PC_ILS
)))){
372 smc
->e
.sb_flag
= TRUE
;
373 DB_ECMN(1, "ECM : EC6_CHECK - stuck bypass");
374 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
375 FDDI_SMT_ERROR
, (u_long
) FDDI_BYPASS_STUCK
,
376 smt_get_error_word(smc
));
379 else if (cmd
== EC_DISCONNECT
) {
380 smc
->e
.ecm_line_state
= FALSE
;
381 GO_STATE(EC7_DEINSERT
) ;
388 start_ecm_timer(smc
,smc
->s
.ecm_check_poll
,0) ;
391 case ACTIONS(EC7_DEINSERT
) :
392 sm_pm_bypass_req(smc
,BP_DEINSERT
);
393 start_ecm_timer(smc
,smc
->s
.ecm_i_max
,EC_TIMEOUT_IMAX
) ;
398 if (cmd
== EC_TIMEOUT_IMAX
) {
403 else if (cmd
== EC_CONNECT
&& smc
->e
.path_test
== PT_PASSED
) {
404 GO_STATE(EC5_INSERT
) ;
409 SMT_PANIC(smc
,SMT_E0107
, SMT_E0107_MSG
) ;
416 * trace propagation actions for SAS & DAS
418 static void prop_actions(struct s_smc
*smc
)
423 RS_SET(smc
,RS_EVENT
) ;
424 switch (smc
->s
.sas
) {
426 port_in
= port_out
= pcm_get_s_port(smc
) ;
429 port_in
= cfm_get_mac_input(smc
) ; /* PA or PB */
430 port_out
= cfm_get_mac_output(smc
) ; /* PA or PB */
433 SMT_PANIC(smc
,SMT_E0108
, SMT_E0108_MSG
) ;
437 DB_ECM("ECM : prop_actions - trace_prop %lu", smc
->e
.trace_prop
);
438 DB_ECM("ECM : prop_actions - in %d out %d", port_in
, port_out
);
440 if (smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_MAC
)) {
441 /* trace initiatior */
442 DB_ECM("ECM : initiate TRACE on PHY %c", 'A' + port_in
- PA
);
443 queue_event(smc
,EVENT_PCM
+port_in
,PC_TRACE
) ;
445 else if ((smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_PHY(PA
))) &&
447 /* trace propagate upstream */
448 DB_ECM("ECM : propagate TRACE on PHY B");
449 queue_event(smc
,EVENT_PCMB
,PC_TRACE
) ;
451 else if ((smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_PHY(PB
))) &&
453 /* trace propagate upstream */
454 DB_ECM("ECM : propagate TRACE on PHY A");
455 queue_event(smc
,EVENT_PCMA
,PC_TRACE
) ;
458 /* signal trace termination */
459 DB_ECM("ECM : TRACE terminated");
460 smc
->e
.path_test
= PT_PENDING
;
462 smc
->e
.trace_prop
= 0 ;
466 * trace propagation actions for Concentrator
468 static void prop_actions(struct s_smc
*smc
)
474 RS_SET(smc
,RS_EVENT
) ;
475 while (smc
->e
.trace_prop
) {
476 DB_ECM("ECM : prop_actions - trace_prop %d",
479 if (smc
->e
.trace_prop
& ENTITY_BIT(ENTITY_MAC
)) {
480 initiator
= ENTITY_MAC
;
481 smc
->e
.trace_prop
&= ~ENTITY_BIT(ENTITY_MAC
) ;
482 DB_ECM("ECM: MAC initiates trace");
485 for (p
= NUMPHYS
-1 ; p
>= 0 ; p
--) {
486 if (smc
->e
.trace_prop
&
487 ENTITY_BIT(ENTITY_PHY(p
)))
490 initiator
= ENTITY_PHY(p
) ;
491 smc
->e
.trace_prop
&= ~ENTITY_BIT(ENTITY_PHY(p
)) ;
493 upstream
= cem_get_upstream(smc
,initiator
) ;
495 if (upstream
== ENTITY_MAC
) {
496 /* signal trace termination */
497 DB_ECM("ECM : TRACE terminated");
498 smc
->e
.path_test
= PT_PENDING
;
501 /* trace propagate upstream */
502 DB_ECM("ECM : propagate TRACE on PHY %d", upstream
);
503 queue_event(smc
,EVENT_PCM
+upstream
,PC_TRACE
) ;
511 * SMT timer interface
514 static void start_ecm_timer(struct s_smc
*smc
, u_long value
, int event
)
516 smt_timer_start(smc
,&smc
->e
.ecm_timer
,value
,EV_TOKEN(EVENT_ECM
,event
));
520 * SMT timer interface
523 static void stop_ecm_timer(struct s_smc
*smc
)
525 if (smc
->e
.ecm_timer
.tm_active
)
526 smt_timer_stop(smc
,&smc
->e
.ecm_timer
) ;