1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#include "h/types.h"
42#include "h/fddi.h"
43#include "h/smc.h"
44
45#define KERNEL
46#include "h/smtstate.h"
47
48#ifndef lint
49static const char ID_sccs[] = "@(#)ecm.c 2.7 99/08/05 (C) SK " ;
50#endif
51
52
53
54
55#define AFLAG 0x10
56#define GO_STATE(x) (smc->mib.fddiSMTECMState = (x)|AFLAG)
57#define ACTIONS_DONE() (smc->mib.fddiSMTECMState &= ~AFLAG)
58#define ACTIONS(x) (x|AFLAG)
59
60#define EC0_OUT 0
61#define EC1_IN 1
62#define EC2_TRACE 2
63#define EC3_LEAVE 3
64#define EC4_PATH_TEST 4
65#define EC5_INSERT 5
66#define EC6_CHECK 6
67#define EC7_DEINSERT 7
68
69#ifdef DEBUG
70
71
72
73static const char * const ecm_states[] = {
74 "EC0_OUT","EC1_IN","EC2_TRACE","EC3_LEAVE","EC4_PATH_TEST",
75 "EC5_INSERT","EC6_CHECK","EC7_DEINSERT"
76} ;
77
78
79
80
81static 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"
85} ;
86#endif
87
88
89
90
91
92
93
94
95
96
97static void ecm_fsm(struct s_smc *smc, int cmd);
98static void start_ecm_timer(struct s_smc *smc, u_long value, int event);
99static void stop_ecm_timer(struct s_smc *smc);
100static void prop_actions(struct s_smc *smc);
101
102
103
104
105
106void ecm_init(struct s_smc *smc)
107{
108 smc->e.path_test = PT_PASSED ;
109 smc->e.trace_prop = 0 ;
110 smc->e.sb_flag = 0 ;
111 smc->mib.fddiSMTECMState = ACTIONS(EC0_OUT) ;
112 smc->e.ecm_line_state = FALSE ;
113}
114
115
116
117
118
119
120
121
122
123
124void ecm(struct s_smc *smc, int event)
125{
126 int state ;
127
128 do {
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 ;
134 ecm_fsm(smc,event) ;
135 event = 0 ;
136 } while (state != smc->mib.fddiSMTECMState) ;
137 ecm_state_change(smc,(int)smc->mib.fddiSMTECMState) ;
138}
139
140
141
142
143static void ecm_fsm(struct s_smc *smc, int cmd)
144{
145 int ls_a ;
146 int ls_b ;
147 int p ;
148
149
150 smc->mib.fddiSMTBypassPresent = sm_pm_bypass_present(smc) ;
151 if (cmd == EC_CONNECT)
152 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
153
154
155
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) );
161
162
163 if (cmd == EC_CONNECT) {
164 smc->e.DisconnectFlag = FALSE ;
165 }
166 else if (cmd == EC_DISCONNECT) {
167 smc->e.DisconnectFlag = TRUE ;
168 }
169
170 switch(smc->mib.fddiSMTECMState) {
171 case ACTIONS(EC0_OUT) :
172
173
174
175 smc->e.path_test = PT_PASSED ;
176 smc->e.ecm_line_state = FALSE ;
177 stop_ecm_timer(smc) ;
178 ACTIONS_DONE() ;
179 break ;
180 case EC0_OUT:
181
182 if (cmd == EC_CONNECT && !smc->mib.fddiSMTBypassPresent
183 && smc->e.path_test==PT_PASSED) {
184 GO_STATE(EC1_IN) ;
185 break ;
186 }
187
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) ;
192 break ;
193 }
194 break;
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) ;
202 ACTIONS_DONE() ;
203 break ;
204 case EC1_IN:
205
206 if (cmd == EC_TRACE_PROP) {
207 prop_actions(smc) ;
208 GO_STATE(EC2_TRACE) ;
209 break ;
210 }
211
212 else if (cmd == EC_DISCONNECT) {
213 GO_STATE(EC3_LEAVE) ;
214 break ;
215 }
216 break;
217 case ACTIONS(EC2_TRACE) :
218 start_ecm_timer(smc,MIB2US(smc->mib.fddiSMTTrace_MaxExpiration),
219 EC_TIMEOUT_TMAX) ;
220 ACTIONS_DONE() ;
221 break ;
222 case EC2_TRACE :
223
224 if (cmd == EC_TRACE_PROP) {
225 prop_actions(smc) ;
226 GO_STATE(EC2_TRACE) ;
227 break ;
228 }
229
230 else if (cmd == EC_DISCONNECT) {
231 smc->e.path_test = PT_EXITING ;
232 GO_STATE(EC3_LEAVE) ;
233 break ;
234 }
235
236 else if (smc->e.path_test == PT_PENDING) {
237 GO_STATE(EC3_LEAVE) ;
238 break ;
239 }
240
241 else if (cmd == EC_TIMEOUT_TMAX) {
242
243
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) ;
249 break ;
250 }
251 break ;
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) ;
256 ACTIONS_DONE() ;
257 break ;
258 case EC3_LEAVE:
259
260 if (cmd == EC_TIMEOUT_TD && !smc->mib.fddiSMTBypassPresent &&
261 (smc->e.path_test != PT_PENDING)) {
262 GO_STATE(EC0_OUT) ;
263 break ;
264 }
265
266 else if (cmd == EC_TIMEOUT_TD &&
267 (smc->e.path_test == PT_PENDING)) {
268 GO_STATE(EC4_PATH_TEST) ;
269 break ;
270 }
271
272 else if (cmd == EC_CONNECT && smc->e.path_test == PT_PASSED) {
273 GO_STATE(EC1_IN) ;
274 break ;
275 }
276
277 else if (cmd == EC_DISCONNECT &&
278 smc->e.path_test == PT_PENDING) {
279 smc->e.path_test = PT_EXITING ;
280
281
282
283 }
284
285 else if (cmd == EC_TIMEOUT_TD &&
286 smc->mib.fddiSMTBypassPresent &&
287 smc->e.path_test != PT_PENDING) {
288 GO_STATE(EC7_DEINSERT) ;
289 break ;
290 }
291 break ;
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
297 ACTIONS_DONE() ;
298 break ;
299 case EC4_PATH_TEST :
300
301 if (cmd == EC_TEST_DONE)
302 smc->e.path_test = PT_PASSED ;
303
304 if (smc->e.path_test == PT_FAILED)
305 RS_SET(smc,RS_PATHTEST) ;
306
307
308 if (smc->e.path_test == PT_FAILED &&
309 !smc->mib.fddiSMTBypassPresent) {
310 GO_STATE(EC0_OUT) ;
311 break ;
312 }
313
314 else if (cmd == EC_DISCONNECT &&
315 !smc->mib.fddiSMTBypassPresent) {
316 GO_STATE(EC0_OUT) ;
317 break ;
318 }
319
320 else if (smc->e.path_test == PT_PASSED) {
321 GO_STATE(EC1_IN) ;
322 break ;
323 }
324
325 else if (smc->e.path_test == PT_FAILED &&
326 smc->mib.fddiSMTBypassPresent) {
327 GO_STATE(EC7_DEINSERT) ;
328 break ;
329 }
330
331 else if (cmd == EC_DISCONNECT &&
332 smc->mib.fddiSMTBypassPresent) {
333 GO_STATE(EC7_DEINSERT) ;
334 break ;
335 }
336 break ;
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) ;
340 ACTIONS_DONE() ;
341 break ;
342 case EC5_INSERT :
343
344 if (cmd == EC_TIMEOUT_INMAX) {
345 GO_STATE(EC6_CHECK) ;
346 break ;
347 }
348
349 else if (cmd == EC_DISCONNECT) {
350 GO_STATE(EC7_DEINSERT) ;
351 break ;
352 }
353 break ;
354 case ACTIONS(EC6_CHECK) :
355
356
357
358
359 start_ecm_timer(smc,smc->s.ecm_check_poll,0) ;
360 smc->e.ecm_line_state = TRUE ;
361 (void) sm_pm_ls_latch(smc,PA,1) ;
362 (void) sm_pm_ls_latch(smc,PB,1) ;
363 ACTIONS_DONE() ;
364 break ;
365 case EC6_CHECK :
366 ls_a = sm_pm_get_ls(smc,PA) ;
367 ls_b = sm_pm_get_ls(smc,PB) ;
368
369
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 ;
374 GO_STATE(EC1_IN) ;
375 break ;
376 }
377
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));
386 }
387
388 else if (cmd == EC_DISCONNECT) {
389 smc->e.ecm_line_state = FALSE ;
390 GO_STATE(EC7_DEINSERT) ;
391 break ;
392 }
393 else {
394
395
396
397 start_ecm_timer(smc,smc->s.ecm_check_poll,0) ;
398 }
399 break ;
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) ;
403 ACTIONS_DONE() ;
404 break ;
405 case EC7_DEINSERT:
406
407 if (cmd == EC_TIMEOUT_IMAX) {
408 GO_STATE(EC0_OUT) ;
409 break ;
410 }
411
412 else if (cmd == EC_CONNECT && smc->e.path_test == PT_PASSED) {
413 GO_STATE(EC5_INSERT) ;
414 break ;
415 }
416 break;
417 default:
418 SMT_PANIC(smc,SMT_E0107, SMT_E0107_MSG) ;
419 break;
420 }
421}
422
423#ifndef CONCENTRATOR
424
425
426
427static void prop_actions(struct s_smc *smc)
428{
429 int port_in = 0 ;
430 int port_out = 0 ;
431
432 RS_SET(smc,RS_EVENT) ;
433 switch (smc->s.sas) {
434 case SMT_SAS :
435 port_in = port_out = pcm_get_s_port(smc) ;
436 break ;
437 case SMT_DAS :
438 port_in = cfm_get_mac_input(smc) ;
439 port_out = cfm_get_mac_output(smc) ;
440 break ;
441 case SMT_NAC :
442 SMT_PANIC(smc,SMT_E0108, SMT_E0108_MSG) ;
443 return ;
444 }
445
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) ;
448
449 if (smc->e.trace_prop & ENTITY_BIT(ENTITY_MAC)) {
450
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) ;
453 }
454 else if ((smc->e.trace_prop & ENTITY_BIT(ENTITY_PHY(PA))) &&
455 port_out != PA) {
456
457 DB_ECM("ECM : propagate TRACE on PHY B\n",0,0) ;
458 queue_event(smc,EVENT_PCMB,PC_TRACE) ;
459 }
460 else if ((smc->e.trace_prop & ENTITY_BIT(ENTITY_PHY(PB))) &&
461 port_out != PB) {
462
463 DB_ECM("ECM : propagate TRACE on PHY A\n",0,0) ;
464 queue_event(smc,EVENT_PCMA,PC_TRACE) ;
465 }
466 else {
467
468 DB_ECM("ECM : TRACE terminated\n",0,0) ;
469 smc->e.path_test = PT_PENDING ;
470 }
471 smc->e.trace_prop = 0 ;
472}
473#else
474
475
476
477static void prop_actions(struct s_smc *smc)
478{
479 int initiator ;
480 int upstream ;
481 int p ;
482
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) ;
487
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) ;
492 }
493 else {
494 for (p = NUMPHYS-1 ; p >= 0 ; p--) {
495 if (smc->e.trace_prop &
496 ENTITY_BIT(ENTITY_PHY(p)))
497 break ;
498 }
499 initiator = ENTITY_PHY(p) ;
500 smc->e.trace_prop &= ~ENTITY_BIT(ENTITY_PHY(p)) ;
501 }
502 upstream = cem_get_upstream(smc,initiator) ;
503
504 if (upstream == ENTITY_MAC) {
505
506 DB_ECM("ECM : TRACE terminated\n",0,0) ;
507 smc->e.path_test = PT_PENDING ;
508 }
509 else {
510
511 DB_ECM("ECM : propagate TRACE on PHY %d\n",upstream,0) ;
512 queue_event(smc,EVENT_PCM+upstream,PC_TRACE) ;
513 }
514 }
515}
516#endif
517
518
519
520
521
522
523static void start_ecm_timer(struct s_smc *smc, u_long value, int event)
524{
525 smt_timer_start(smc,&smc->e.ecm_timer,value,EV_TOKEN(EVENT_ECM,event));
526}
527
528
529
530
531
532static void stop_ecm_timer(struct s_smc *smc)
533{
534 if (smc->e.ecm_timer.tm_active)
535 smt_timer_stop(smc,&smc->e.ecm_timer) ;
536}
537