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 ******************************************************************************/
23 * Hardware independent state machine implemantation
24 * The following external SMT functions are referenced :
30 * The following external HW dependent functions are referenced :
32 * sm_mac_check_beacon_claim()
34 * The following HW dependent events are required :
50 #include "h/smtstate.h"
53 static const char ID_sccs
[] = "@(#)rmt.c 2.13 99/07/02 (C) SK " ;
60 #define GO_STATE(x) (smc->mib.m[MAC0].fddiMACRMTState = (x)|AFLAG)
61 #define ACTIONS_DONE() (smc->mib.m[MAC0].fddiMACRMTState &= ~AFLAG)
62 #define ACTIONS(x) (x|AFLAG)
64 #define RM0_ISOLATED 0
65 #define RM1_NON_OP 1 /* not operational */
66 #define RM2_RING_OP 2 /* ring operational */
67 #define RM3_DETECT 3 /* detect dupl addresses */
68 #define RM4_NON_OP_DUP 4 /* dupl. addr detected */
69 #define RM5_RING_OP_DUP 5 /* ring oper. with dupl. addr */
70 #define RM6_DIRECTED 6 /* sending directed beacons */
71 #define RM7_TRACE 7 /* trace initiated */
74 * symbolic state names
76 static const char * const rmt_states
[] = {
77 "RM0_ISOLATED","RM1_NON_OP","RM2_RING_OP","RM3_DETECT",
78 "RM4_NON_OP_DUP","RM5_RING_OP_DUP","RM6_DIRECTED",
83 * symbolic event names
85 static const char * const rmt_events
[] = {
86 "NONE","RM_RING_OP","RM_RING_NON_OP","RM_MY_BEACON",
87 "RM_OTHER_BEACON","RM_MY_CLAIM","RM_TRT_EXP","RM_VALID_CLAIM",
88 "RM_JOIN","RM_LOOP","RM_DUP_ADDR","RM_ENABLE_FLAG",
89 "RM_TIMEOUT_NON_OP","RM_TIMEOUT_T_STUCK",
90 "RM_TIMEOUT_ANNOUNCE","RM_TIMEOUT_T_DIRECT",
91 "RM_TIMEOUT_D_MAX","RM_TIMEOUT_POLL","RM_TX_STATE_CHANGE"
101 * function declarations
103 static void rmt_fsm(struct s_smc
*smc
, int cmd
);
104 static void start_rmt_timer0(struct s_smc
*smc
, u_long value
, int event
);
105 static void start_rmt_timer1(struct s_smc
*smc
, u_long value
, int event
);
106 static void start_rmt_timer2(struct s_smc
*smc
, u_long value
, int event
);
107 static void stop_rmt_timer0(struct s_smc
*smc
);
108 static void stop_rmt_timer1(struct s_smc
*smc
);
109 static void stop_rmt_timer2(struct s_smc
*smc
);
110 static void rmt_dup_actions(struct s_smc
*smc
);
111 static void rmt_reinsert_actions(struct s_smc
*smc
);
112 static void rmt_leave_actions(struct s_smc
*smc
);
113 static void rmt_new_dup_actions(struct s_smc
*smc
);
116 extern void restart_trt_for_dbcn() ;
117 #endif /*SUPERNET_3*/
120 init RMT state machine
121 clear all RMT vars and flags
123 void rmt_init(struct s_smc
*smc
)
125 smc
->mib
.m
[MAC0
].fddiMACRMTState
= ACTIONS(RM0_ISOLATED
) ;
126 smc
->r
.dup_addr_test
= DA_NONE
;
128 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= FALSE
;
129 smc
->r
.sm_ma_avail
= FALSE
;
130 smc
->r
.loop_avail
= 0 ;
133 smc
->r
.no_flag
= TRUE
;
145 void rmt(struct s_smc
*smc
, int event
)
150 DB_RMT("RMT : state %s%s event %s",
151 smc
->mib
.m
[MAC0
].fddiMACRMTState
& AFLAG
? "ACTIONS " : "",
152 rmt_states
[smc
->mib
.m
[MAC0
].fddiMACRMTState
& ~AFLAG
],
154 state
= smc
->mib
.m
[MAC0
].fddiMACRMTState
;
157 } while (state
!= smc
->mib
.m
[MAC0
].fddiMACRMTState
) ;
158 rmt_state_change(smc
,(int)smc
->mib
.m
[MAC0
].fddiMACRMTState
) ;
164 static void rmt_fsm(struct s_smc
*smc
, int cmd
)
167 * RM00-RM70 : from all states
169 if (!smc
->r
.rm_join
&& !smc
->r
.rm_loop
&&
170 smc
->mib
.m
[MAC0
].fddiMACRMTState
!= ACTIONS(RM0_ISOLATED
) &&
171 smc
->mib
.m
[MAC0
].fddiMACRMTState
!= RM0_ISOLATED
) {
172 RS_SET(smc
,RS_NORINGOP
) ;
173 rmt_indication(smc
,0) ;
174 GO_STATE(RM0_ISOLATED
) ;
178 switch(smc
->mib
.m
[MAC0
].fddiMACRMTState
) {
179 case ACTIONS(RM0_ISOLATED
) :
180 stop_rmt_timer0(smc
) ;
181 stop_rmt_timer1(smc
) ;
182 stop_rmt_timer2(smc
) ;
187 sm_ma_control(smc
,MA_OFFLINE
) ;
188 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= FALSE
;
189 smc
->r
.loop_avail
= FALSE
;
190 smc
->r
.sm_ma_avail
= FALSE
;
191 smc
->r
.no_flag
= TRUE
;
192 DB_RMTN(1, "RMT : ISOLATED");
197 if (smc
->r
.rm_join
|| smc
->r
.rm_loop
) {
199 * According to the standard the MAC must be reset
200 * here. The FORMAC will be initialized and Claim
201 * and Beacon Frames will be uploaded to the MAC.
202 * So any change of Treq will take effect NOW.
204 sm_ma_control(smc
,MA_RESET
) ;
205 GO_STATE(RM1_NON_OP
) ;
209 case ACTIONS(RM1_NON_OP
) :
210 start_rmt_timer0(smc
,smc
->s
.rmt_t_non_op
,RM_TIMEOUT_NON_OP
) ;
211 stop_rmt_timer1(smc
) ;
212 stop_rmt_timer2(smc
) ;
213 sm_ma_control(smc
,MA_BEACON
) ;
214 DB_RMTN(1, "RMT : RING DOWN");
215 RS_SET(smc
,RS_NORINGOP
) ;
216 smc
->r
.sm_ma_avail
= FALSE
;
217 rmt_indication(smc
,0) ;
222 if (cmd
== RM_RING_OP
) {
223 RS_SET(smc
,RS_RINGOPCHANGE
) ;
224 GO_STATE(RM2_RING_OP
) ;
228 else if (cmd
== RM_TIMEOUT_NON_OP
) {
229 smc
->r
.bn_flag
= FALSE
;
230 smc
->r
.no_flag
= TRUE
;
231 GO_STATE(RM3_DETECT
) ;
235 case ACTIONS(RM2_RING_OP
) :
236 stop_rmt_timer0(smc
) ;
237 stop_rmt_timer1(smc
) ;
238 stop_rmt_timer2(smc
) ;
239 smc
->r
.no_flag
= FALSE
;
241 smc
->r
.loop_avail
= TRUE
;
242 if (smc
->r
.rm_join
) {
243 smc
->r
.sm_ma_avail
= TRUE
;
244 if (smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataEnable
)
245 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= TRUE
;
247 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= FALSE
;
249 DB_RMTN(1, "RMT : RING UP");
250 RS_CLEAR(smc
,RS_NORINGOP
) ;
251 RS_SET(smc
,RS_RINGOPCHANGE
) ;
252 rmt_indication(smc
,1) ;
253 smt_stat_counter(smc
,0) ;
258 if (cmd
== RM_RING_NON_OP
) {
259 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= FALSE
;
260 smc
->r
.loop_avail
= FALSE
;
261 RS_SET(smc
,RS_RINGOPCHANGE
) ;
262 GO_STATE(RM1_NON_OP
) ;
266 else if (cmd
== RM_ENABLE_FLAG
) {
267 if (smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataEnable
)
268 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= TRUE
;
270 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= FALSE
;
273 else if (smc
->r
.dup_addr_test
== DA_FAILED
) {
274 smc
->mib
.m
[MAC0
].fddiMACMA_UnitdataAvailable
= FALSE
;
275 smc
->r
.loop_avail
= FALSE
;
276 smc
->r
.da_flag
= TRUE
;
277 GO_STATE(RM5_RING_OP_DUP
) ;
281 case ACTIONS(RM3_DETECT
) :
282 start_rmt_timer0(smc
,smc
->s
.mac_d_max
*2,RM_TIMEOUT_D_MAX
) ;
283 start_rmt_timer1(smc
,smc
->s
.rmt_t_stuck
,RM_TIMEOUT_T_STUCK
) ;
284 start_rmt_timer2(smc
,smc
->s
.rmt_t_poll
,RM_TIMEOUT_POLL
) ;
285 sm_mac_check_beacon_claim(smc
) ;
286 DB_RMTN(1, "RMT : RM3_DETECT");
290 if (cmd
== RM_TIMEOUT_POLL
) {
291 start_rmt_timer2(smc
,smc
->s
.rmt_t_poll
,RM_TIMEOUT_POLL
);
292 sm_mac_check_beacon_claim(smc
) ;
295 if (cmd
== RM_TIMEOUT_D_MAX
) {
296 smc
->r
.timer0_exp
= TRUE
;
300 * We need a time ">= 2*mac_d_max" since we had finished
301 * Claim or Beacon state. So we will restart timer0 at
302 * every state change.
304 if (cmd
== RM_TX_STATE_CHANGE
) {
305 start_rmt_timer0(smc
,
310 if (cmd
== RM_RING_OP
) {
311 GO_STATE(RM2_RING_OP
) ;
315 else if ((cmd
== RM_MY_BEACON
|| cmd
== RM_OTHER_BEACON
)
317 smc
->r
.bn_flag
= FALSE
;
320 else if (cmd
== RM_TRT_EXP
&& !smc
->r
.bn_flag
) {
323 * set bn_flag only if in state T4 or T5:
324 * only if we're the beaconer should we start the
327 if ((tx
= sm_mac_get_tx_state(smc
)) == 4 || tx
== 5) {
328 DB_RMTN(2, "RMT : DETECT && TRT_EXPIRED && T4/T5");
329 smc
->r
.bn_flag
= TRUE
;
331 * If one of the upstream stations beaconed
332 * and the link to the upstream neighbor is
333 * lost we need to restart the stuck timer to
334 * check the "stuck beacon" condition.
336 start_rmt_timer1(smc
,smc
->s
.rmt_t_stuck
,
337 RM_TIMEOUT_T_STUCK
) ;
340 * We do NOT need to clear smc->r.bn_flag in case of
341 * not being in state T4 or T5, because the flag
342 * must be cleared in order to get in this condition.
345 DB_RMTN(2, "RMT : sm_mac_get_tx_state() = %d (bn_flag = %d)",
349 else if (cmd
== RM_MY_CLAIM
&& smc
->r
.timer0_exp
) {
350 rmt_new_dup_actions(smc
) ;
351 GO_STATE(RM4_NON_OP_DUP
) ;
355 else if (cmd
== RM_MY_BEACON
&& smc
->r
.timer0_exp
) {
356 rmt_new_dup_actions(smc
) ;
357 GO_STATE(RM4_NON_OP_DUP
) ;
361 else if (cmd
== RM_VALID_CLAIM
) {
362 rmt_new_dup_actions(smc
) ;
363 GO_STATE(RM4_NON_OP_DUP
) ;
367 else if (cmd
== RM_TIMEOUT_T_STUCK
&&
368 smc
->r
.rm_join
&& smc
->r
.bn_flag
) {
369 GO_STATE(RM6_DIRECTED
) ;
373 case ACTIONS(RM4_NON_OP_DUP
) :
374 start_rmt_timer0(smc
,smc
->s
.rmt_t_announce
,RM_TIMEOUT_ANNOUNCE
);
375 start_rmt_timer1(smc
,smc
->s
.rmt_t_stuck
,RM_TIMEOUT_T_STUCK
) ;
376 start_rmt_timer2(smc
,smc
->s
.rmt_t_poll
,RM_TIMEOUT_POLL
) ;
377 sm_mac_check_beacon_claim(smc
) ;
378 DB_RMTN(1, "RMT : RM4_NON_OP_DUP");
381 case RM4_NON_OP_DUP
:
382 if (cmd
== RM_TIMEOUT_POLL
) {
383 start_rmt_timer2(smc
,smc
->s
.rmt_t_poll
,RM_TIMEOUT_POLL
);
384 sm_mac_check_beacon_claim(smc
) ;
388 if (!smc
->r
.da_flag
) {
389 GO_STATE(RM1_NON_OP
) ;
393 else if ((cmd
== RM_MY_BEACON
|| cmd
== RM_OTHER_BEACON
) &&
395 smc
->r
.bn_flag
= FALSE
;
398 else if (cmd
== RM_TRT_EXP
&& !smc
->r
.bn_flag
) {
401 * set bn_flag only if in state T4 or T5:
402 * only if we're the beaconer should we start the
405 if ((tx
= sm_mac_get_tx_state(smc
)) == 4 || tx
== 5) {
406 DB_RMTN(2, "RMT : NOPDUP && TRT_EXPIRED && T4/T5");
407 smc
->r
.bn_flag
= TRUE
;
409 * If one of the upstream stations beaconed
410 * and the link to the upstream neighbor is
411 * lost we need to restart the stuck timer to
412 * check the "stuck beacon" condition.
414 start_rmt_timer1(smc
,smc
->s
.rmt_t_stuck
,
415 RM_TIMEOUT_T_STUCK
) ;
418 * We do NOT need to clear smc->r.bn_flag in case of
419 * not being in state T4 or T5, because the flag
420 * must be cleared in order to get in this condition.
423 DB_RMTN(2, "RMT : sm_mac_get_tx_state() = %d (bn_flag = %d)",
427 else if (cmd
== RM_TIMEOUT_ANNOUNCE
&& !smc
->r
.bn_flag
) {
428 rmt_dup_actions(smc
) ;
431 else if (cmd
== RM_RING_OP
) {
432 smc
->r
.no_flag
= FALSE
;
433 GO_STATE(RM5_RING_OP_DUP
) ;
437 else if (cmd
== RM_TIMEOUT_T_STUCK
&&
438 smc
->r
.rm_join
&& smc
->r
.bn_flag
) {
439 GO_STATE(RM6_DIRECTED
) ;
443 case ACTIONS(RM5_RING_OP_DUP
) :
444 stop_rmt_timer0(smc
) ;
445 stop_rmt_timer1(smc
) ;
446 stop_rmt_timer2(smc
) ;
447 DB_RMTN(1, "RMT : RM5_RING_OP_DUP");
450 case RM5_RING_OP_DUP
:
452 if (smc
->r
.dup_addr_test
== DA_PASSED
) {
453 smc
->r
.da_flag
= FALSE
;
454 GO_STATE(RM2_RING_OP
) ;
458 else if (cmd
== RM_RING_NON_OP
) {
459 smc
->r
.jm_flag
= FALSE
;
460 smc
->r
.bn_flag
= FALSE
;
461 GO_STATE(RM4_NON_OP_DUP
) ;
465 case ACTIONS(RM6_DIRECTED
) :
466 start_rmt_timer0(smc
,smc
->s
.rmt_t_direct
,RM_TIMEOUT_T_DIRECT
) ;
467 stop_rmt_timer1(smc
) ;
468 start_rmt_timer2(smc
,smc
->s
.rmt_t_poll
,RM_TIMEOUT_POLL
) ;
469 sm_ma_control(smc
,MA_DIRECTED
) ;
470 RS_SET(smc
,RS_BEACON
) ;
471 DB_RMTN(1, "RMT : RM6_DIRECTED");
476 if (cmd
== RM_TIMEOUT_POLL
) {
477 start_rmt_timer2(smc
,smc
->s
.rmt_t_poll
,RM_TIMEOUT_POLL
);
478 sm_mac_check_beacon_claim(smc
) ;
480 /* Because of problems with the Supernet II chip set
481 * sending of Directed Beacon will stop after 165ms
482 * therefore restart_trt_for_dbcn(smc) will be called
485 restart_trt_for_dbcn(smc
) ;
486 #endif /*SUPERNET_3*/
489 if ((cmd
== RM_MY_BEACON
|| cmd
== RM_OTHER_BEACON
) &&
491 smc
->r
.bn_flag
= FALSE
;
492 GO_STATE(RM3_DETECT
) ;
496 else if ((cmd
== RM_MY_BEACON
|| cmd
== RM_OTHER_BEACON
) &&
498 smc
->r
.bn_flag
= FALSE
;
499 GO_STATE(RM4_NON_OP_DUP
) ;
503 else if (cmd
== RM_TIMEOUT_T_DIRECT
) {
504 GO_STATE(RM7_TRACE
) ;
508 case ACTIONS(RM7_TRACE
) :
509 stop_rmt_timer0(smc
) ;
510 stop_rmt_timer1(smc
) ;
511 stop_rmt_timer2(smc
) ;
512 smc
->e
.trace_prop
|= ENTITY_BIT(ENTITY_MAC
) ;
513 queue_event(smc
,EVENT_ECM
,EC_TRACE_PROP
) ;
514 DB_RMTN(1, "RMT : RM7_TRACE");
520 SMT_PANIC(smc
,SMT_E0122
, SMT_E0122_MSG
) ;
526 * (jd) RMT duplicate address actions
527 * leave the ring or reinsert just as configured
529 static void rmt_dup_actions(struct s_smc
*smc
)
531 if (smc
->r
.jm_flag
) {
534 if (smc
->s
.rmt_dup_mac_behavior
) {
535 SMT_ERR_LOG(smc
,SMT_E0138
, SMT_E0138_MSG
) ;
536 rmt_reinsert_actions(smc
) ;
539 SMT_ERR_LOG(smc
,SMT_E0135
, SMT_E0135_MSG
) ;
540 rmt_leave_actions(smc
) ;
546 * Reconnect to the Ring
548 static void rmt_reinsert_actions(struct s_smc
*smc
)
550 queue_event(smc
,EVENT_ECM
,EC_DISCONNECT
) ;
551 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
555 * duplicate address detected
557 static void rmt_new_dup_actions(struct s_smc
*smc
)
559 smc
->r
.da_flag
= TRUE
;
560 smc
->r
.bn_flag
= FALSE
;
561 smc
->r
.jm_flag
= FALSE
;
563 * we have three options : change address, jam or leave
564 * we leave the ring as default
565 * Optionally it's possible to reinsert after leaving the Ring
566 * but this will not conform with SMT Spec.
568 if (smc
->s
.rmt_dup_mac_behavior
) {
569 SMT_ERR_LOG(smc
,SMT_E0138
, SMT_E0138_MSG
) ;
570 rmt_reinsert_actions(smc
) ;
573 SMT_ERR_LOG(smc
,SMT_E0135
, SMT_E0135_MSG
) ;
574 rmt_leave_actions(smc
) ;
582 static void rmt_leave_actions(struct s_smc
*smc
)
584 queue_event(smc
,EVENT_ECM
,EC_DISCONNECT
) ;
586 * Note: Do NOT try again later. (with please reconnect)
587 * The station must be left from the ring!
592 * SMT timer interface
595 static void start_rmt_timer0(struct s_smc
*smc
, u_long value
, int event
)
597 smc
->r
.timer0_exp
= FALSE
; /* clear timer event flag */
598 smt_timer_start(smc
,&smc
->r
.rmt_timer0
,value
,EV_TOKEN(EVENT_RMT
,event
));
602 * SMT timer interface
605 static void start_rmt_timer1(struct s_smc
*smc
, u_long value
, int event
)
607 smc
->r
.timer1_exp
= FALSE
; /* clear timer event flag */
608 smt_timer_start(smc
,&smc
->r
.rmt_timer1
,value
,EV_TOKEN(EVENT_RMT
,event
));
612 * SMT timer interface
615 static void start_rmt_timer2(struct s_smc
*smc
, u_long value
, int event
)
617 smc
->r
.timer2_exp
= FALSE
; /* clear timer event flag */
618 smt_timer_start(smc
,&smc
->r
.rmt_timer2
,value
,EV_TOKEN(EVENT_RMT
,event
));
622 * SMT timer interface
625 static void stop_rmt_timer0(struct s_smc
*smc
)
627 if (smc
->r
.rmt_timer0
.tm_active
)
628 smt_timer_stop(smc
,&smc
->r
.rmt_timer0
) ;
632 * SMT timer interface
635 static void stop_rmt_timer1(struct s_smc
*smc
)
637 if (smc
->r
.rmt_timer1
.tm_active
)
638 smt_timer_stop(smc
,&smc
->r
.rmt_timer1
) ;
642 * SMT timer interface
645 static void stop_rmt_timer2(struct s_smc
*smc
)
647 if (smc
->r
.rmt_timer2
.tm_active
)
648 smt_timer_stop(smc
,&smc
->r
.rmt_timer2
) ;