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(struct s_smc *smc, int cmd);
98
static void start_ecm_timer(struct s_smc *smc, u_long value, int event);
99
static void stop_ecm_timer(struct s_smc *smc);
100
static void prop_actions(struct s_smc *smc);
103
init ECM state machine
104
clear all ECM vars and flags
106
void ecm_init(struct s_smc *smc)
108
smc->e.path_test = PT_PASSED ;
109
smc->e.trace_prop = 0 ;
111
smc->mib.fddiSMTECMState = ACTIONS(EC0_OUT) ;
112
smc->e.ecm_line_state = FALSE ;
124
void ecm(struct s_smc *smc, int event)
129
DB_ECM("ECM : state %s%s",
130
(smc->mib.fddiSMTECMState & AFLAG) ? "ACTIONS " : "",
131
ecm_states[smc->mib.fddiSMTECMState & ~AFLAG]) ;
132
DB_ECM(" event %s\n",ecm_events[event],0) ;
133
state = smc->mib.fddiSMTECMState ;
136
} while (state != smc->mib.fddiSMTECMState) ;
137
ecm_state_change(smc,(int)smc->mib.fddiSMTECMState) ;
143
static void ecm_fsm(struct s_smc *smc, int cmd)
145
int ls_a ; /* current line state PHY A */
146
int ls_b ; /* current line state PHY B */
150
smc->mib.fddiSMTBypassPresent = sm_pm_bypass_present(smc) ;
151
if (cmd == EC_CONNECT)
152
smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
154
/* For AIX event notification: */
155
/* Is a disconnect command remotely issued ? */
156
if (cmd == EC_DISCONNECT &&
157
smc->mib.fddiSMTRemoteDisconnectFlag == TRUE)
158
AIX_EVENT (smc, (u_long) CIO_HARD_FAIL, (u_long)
159
FDDI_REMOTE_DISCONNECT, smt_get_event_word(smc),
160
smt_get_error_word(smc) );
162
/*jd 05-Aug-1999 Bug #10419 "Port Disconnect fails at Dup MAc Cond."*/
163
if (cmd == EC_CONNECT) {
164
smc->e.DisconnectFlag = FALSE ;
166
else if (cmd == EC_DISCONNECT) {
167
smc->e.DisconnectFlag = TRUE ;
170
switch(smc->mib.fddiSMTECMState) {
171
case ACTIONS(EC0_OUT) :
173
* We do not perform a path test
175
smc->e.path_test = PT_PASSED ;
176
smc->e.ecm_line_state = FALSE ;
177
stop_ecm_timer(smc) ;
182
if (cmd == EC_CONNECT && !smc->mib.fddiSMTBypassPresent
183
&& smc->e.path_test==PT_PASSED) {
188
else if (cmd == EC_CONNECT && (smc->e.path_test==PT_PASSED) &&
189
smc->mib.fddiSMTBypassPresent &&
190
(smc->s.sas == SMT_DAS)) {
191
GO_STATE(EC5_INSERT) ;
195
case ACTIONS(EC1_IN) :
196
stop_ecm_timer(smc) ;
197
smc->e.trace_prop = 0 ;
198
sm_ma_control(smc,MA_TREQ) ;
199
for (p = 0 ; p < NUMPHYS ; p++)
200
if (smc->mib.p[p].fddiPORTHardwarePresent)
201
queue_event(smc,EVENT_PCMA+p,PC_START) ;
206
if (cmd == EC_TRACE_PROP) {
208
GO_STATE(EC2_TRACE) ;
212
else if (cmd == EC_DISCONNECT) {
213
GO_STATE(EC3_LEAVE) ;
217
case ACTIONS(EC2_TRACE) :
218
start_ecm_timer(smc,MIB2US(smc->mib.fddiSMTTrace_MaxExpiration),
224
if (cmd == EC_TRACE_PROP) {
226
GO_STATE(EC2_TRACE) ;
230
else if (cmd == EC_DISCONNECT) {
231
smc->e.path_test = PT_EXITING ;
232
GO_STATE(EC3_LEAVE) ;
236
else if (smc->e.path_test == PT_PENDING) {
237
GO_STATE(EC3_LEAVE) ;
241
else if (cmd == EC_TIMEOUT_TMAX) {
242
/* Trace_Max is expired */
243
/* -> send AIX_EVENT */
244
AIX_EVENT(smc, (u_long) FDDI_RING_STATUS,
245
(u_long) FDDI_SMT_ERROR, (u_long)
246
FDDI_TRACE_MAX, smt_get_error_word(smc));
247
smc->e.path_test = PT_PENDING ;
248
GO_STATE(EC3_LEAVE) ;
252
case ACTIONS(EC3_LEAVE) :
253
start_ecm_timer(smc,smc->s.ecm_td_min,EC_TIMEOUT_TD) ;
254
for (p = 0 ; p < NUMPHYS ; p++)
255
queue_event(smc,EVENT_PCMA+p,PC_STOP) ;
260
if (cmd == EC_TIMEOUT_TD && !smc->mib.fddiSMTBypassPresent &&
261
(smc->e.path_test != PT_PENDING)) {
266
else if (cmd == EC_TIMEOUT_TD &&
267
(smc->e.path_test == PT_PENDING)) {
268
GO_STATE(EC4_PATH_TEST) ;
272
else if (cmd == EC_CONNECT && smc->e.path_test == PT_PASSED) {
277
else if (cmd == EC_DISCONNECT &&
278
smc->e.path_test == PT_PENDING) {
279
smc->e.path_test = PT_EXITING ;
281
* stay in state - state will be left via timeout
285
else if (cmd == EC_TIMEOUT_TD &&
286
smc->mib.fddiSMTBypassPresent &&
287
smc->e.path_test != PT_PENDING) {
288
GO_STATE(EC7_DEINSERT) ;
292
case ACTIONS(EC4_PATH_TEST) :
293
stop_ecm_timer(smc) ;
294
smc->e.path_test = PT_TESTING ;
295
start_ecm_timer(smc,smc->s.ecm_test_done,EC_TEST_DONE) ;
296
/* now perform path test ... just a simulation */
300
/* path test done delay */
301
if (cmd == EC_TEST_DONE)
302
smc->e.path_test = PT_PASSED ;
304
if (smc->e.path_test == PT_FAILED)
305
RS_SET(smc,RS_PATHTEST) ;
308
if (smc->e.path_test == PT_FAILED &&
309
!smc->mib.fddiSMTBypassPresent) {
314
else if (cmd == EC_DISCONNECT &&
315
!smc->mib.fddiSMTBypassPresent) {
320
else if (smc->e.path_test == PT_PASSED) {
325
else if (smc->e.path_test == PT_FAILED &&
326
smc->mib.fddiSMTBypassPresent) {
327
GO_STATE(EC7_DEINSERT) ;
331
else if (cmd == EC_DISCONNECT &&
332
smc->mib.fddiSMTBypassPresent) {
333
GO_STATE(EC7_DEINSERT) ;
337
case ACTIONS(EC5_INSERT) :
338
sm_pm_bypass_req(smc,BP_INSERT);
339
start_ecm_timer(smc,smc->s.ecm_in_max,EC_TIMEOUT_INMAX) ;
344
if (cmd == EC_TIMEOUT_INMAX) {
345
GO_STATE(EC6_CHECK) ;
349
else if (cmd == EC_DISCONNECT) {
350
GO_STATE(EC7_DEINSERT) ;
354
case ACTIONS(EC6_CHECK) :
356
* in EC6_CHECK, we *POLL* the line state !
357
* check whether both bypass switches have switched.
359
start_ecm_timer(smc,smc->s.ecm_check_poll,0) ;
360
smc->e.ecm_line_state = TRUE ; /* flag to pcm: report Q/HLS */
361
(void) sm_pm_ls_latch(smc,PA,1) ; /* enable line state latch */
362
(void) sm_pm_ls_latch(smc,PB,1) ; /* enable line state latch */
366
ls_a = sm_pm_get_ls(smc,PA) ;
367
ls_b = sm_pm_get_ls(smc,PB) ;
370
if (((ls_a == PC_QLS) || (ls_a == PC_HLS)) &&
371
((ls_b == PC_QLS) || (ls_b == PC_HLS)) ) {
372
smc->e.sb_flag = FALSE ;
373
smc->e.ecm_line_state = FALSE ;
378
else if (!smc->e.sb_flag &&
379
(((ls_a == PC_ILS) && (ls_b == PC_QLS)) ||
380
((ls_a == PC_QLS) && (ls_b == PC_ILS)))){
381
smc->e.sb_flag = TRUE ;
382
DB_ECMN(1,"ECM : EC6_CHECK - stuck bypass\n",0,0) ;
383
AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
384
FDDI_SMT_ERROR, (u_long) FDDI_BYPASS_STUCK,
385
smt_get_error_word(smc));
388
else if (cmd == EC_DISCONNECT) {
389
smc->e.ecm_line_state = FALSE ;
390
GO_STATE(EC7_DEINSERT) ;
397
start_ecm_timer(smc,smc->s.ecm_check_poll,0) ;
400
case ACTIONS(EC7_DEINSERT) :
401
sm_pm_bypass_req(smc,BP_DEINSERT);
402
start_ecm_timer(smc,smc->s.ecm_i_max,EC_TIMEOUT_IMAX) ;
407
if (cmd == EC_TIMEOUT_IMAX) {
412
else if (cmd == EC_CONNECT && smc->e.path_test == PT_PASSED) {
413
GO_STATE(EC5_INSERT) ;
418
SMT_PANIC(smc,SMT_E0107, SMT_E0107_MSG) ;
425
* trace propagation actions for SAS & DAS
427
static void prop_actions(struct s_smc *smc)
432
RS_SET(smc,RS_EVENT) ;
433
switch (smc->s.sas) {
435
port_in = port_out = pcm_get_s_port(smc) ;
438
port_in = cfm_get_mac_input(smc) ; /* PA or PB */
439
port_out = cfm_get_mac_output(smc) ; /* PA or PB */
442
SMT_PANIC(smc,SMT_E0108, SMT_E0108_MSG) ;
446
DB_ECM("ECM : prop_actions - trace_prop %d\n", smc->e.trace_prop,0) ;
447
DB_ECM("ECM : prop_actions - in %d out %d\n", port_in,port_out) ;
449
if (smc->e.trace_prop & ENTITY_BIT(ENTITY_MAC)) {
450
/* trace initiatior */
451
DB_ECM("ECM : initiate TRACE on PHY %c\n",'A'+port_in-PA,0) ;
452
queue_event(smc,EVENT_PCM+port_in,PC_TRACE) ;
454
else if ((smc->e.trace_prop & ENTITY_BIT(ENTITY_PHY(PA))) &&
456
/* trace propagate upstream */
457
DB_ECM("ECM : propagate TRACE on PHY B\n",0,0) ;
458
queue_event(smc,EVENT_PCMB,PC_TRACE) ;
460
else if ((smc->e.trace_prop & ENTITY_BIT(ENTITY_PHY(PB))) &&
462
/* trace propagate upstream */
463
DB_ECM("ECM : propagate TRACE on PHY A\n",0,0) ;
464
queue_event(smc,EVENT_PCMA,PC_TRACE) ;
467
/* signal trace termination */
468
DB_ECM("ECM : TRACE terminated\n",0,0) ;
469
smc->e.path_test = PT_PENDING ;
471
smc->e.trace_prop = 0 ;
475
* trace propagation actions for Concentrator
477
static void prop_actions(struct s_smc *smc)
483
RS_SET(smc,RS_EVENT) ;
484
while (smc->e.trace_prop) {
485
DB_ECM("ECM : prop_actions - trace_prop %d\n",
486
smc->e.trace_prop,0) ;
488
if (smc->e.trace_prop & ENTITY_BIT(ENTITY_MAC)) {
489
initiator = ENTITY_MAC ;
490
smc->e.trace_prop &= ~ENTITY_BIT(ENTITY_MAC) ;
491
DB_ECM("ECM: MAC initiates trace\n",0,0) ;
494
for (p = NUMPHYS-1 ; p >= 0 ; p--) {
495
if (smc->e.trace_prop &
496
ENTITY_BIT(ENTITY_PHY(p)))
499
initiator = ENTITY_PHY(p) ;
500
smc->e.trace_prop &= ~ENTITY_BIT(ENTITY_PHY(p)) ;
502
upstream = cem_get_upstream(smc,initiator) ;
504
if (upstream == ENTITY_MAC) {
505
/* signal trace termination */
506
DB_ECM("ECM : TRACE terminated\n",0,0) ;
507
smc->e.path_test = PT_PENDING ;
510
/* trace propagate upstream */
511
DB_ECM("ECM : propagate TRACE on PHY %d\n",upstream,0) ;
512
queue_event(smc,EVENT_PCM+upstream,PC_TRACE) ;
520
* SMT timer interface
523
static void start_ecm_timer(struct s_smc *smc, u_long value, int event)
525
smt_timer_start(smc,&smc->e.ecm_timer,value,EV_TOKEN(EVENT_ECM,event));
529
* SMT timer interface
532
static void stop_ecm_timer(struct s_smc *smc)
534
if (smc->e.ecm_timer.tm_active)
535
smt_timer_stop(smc,&smc->e.ecm_timer) ;