1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
3 *
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 *
7 * See the file "skfddi.c" for further information.
8 *
9 * The information in this file is provided "AS IS" without warranty.
10 *
11 ******************************************************************************/
12
13 /*
14 SMT Event Queue Management
15 */
16
17 #include "h/types.h"
18 #include "h/fddi.h"
19 #include "h/smc.h"
20
21 #define PRINTF(a,b,c)
22
23 /*
24 * init event queue management
25 */
ev_init(struct s_smc * smc)26 void ev_init(struct s_smc *smc)
27 {
28 smc->q.ev_put = smc->q.ev_get = smc->q.ev_queue ;
29 }
30
31 /*
32 * add event to queue
33 */
queue_event(struct s_smc * smc,int class,int event)34 void queue_event(struct s_smc *smc, int class, int event)
35 {
36 PRINTF("queue class %d event %d\n",class,event) ;
37 smc->q.ev_put->class = class ;
38 smc->q.ev_put->event = event ;
39 if (++smc->q.ev_put == &smc->q.ev_queue[MAX_EVENT])
40 smc->q.ev_put = smc->q.ev_queue ;
41
42 if (smc->q.ev_put == smc->q.ev_get) {
43 SMT_ERR_LOG(smc,SMT_E0137, SMT_E0137_MSG) ;
44 }
45 }
46
47 /*
48 * timer_event is called from HW timer package.
49 */
timer_event(struct s_smc * smc,u_long token)50 void timer_event(struct s_smc *smc, u_long token)
51 {
52 PRINTF("timer event class %d token %d\n",
53 EV_T_CLASS(token),
54 EV_T_EVENT(token)) ;
55 queue_event(smc,EV_T_CLASS(token),EV_T_EVENT(token));
56 }
57
58 /*
59 * event dispatcher
60 * while event queue is not empty
61 * get event from queue
62 * send command to state machine
63 * end
64 */
ev_dispatcher(struct s_smc * smc)65 void ev_dispatcher(struct s_smc *smc)
66 {
67 struct event_queue *ev ; /* pointer into queue */
68 int class ;
69
70 ev = smc->q.ev_get ;
71 PRINTF("dispatch get %x put %x\n",ev,smc->q.ev_put) ;
72 while (ev != smc->q.ev_put) {
73 PRINTF("dispatch class %d event %d\n",ev->class,ev->event) ;
74 switch(class = ev->class) {
75 case EVENT_ECM : /* Entity Corordination Man. */
76 ecm(smc,(int)ev->event) ;
77 break ;
78 case EVENT_CFM : /* Configuration Man. */
79 cfm(smc,(int)ev->event) ;
80 break ;
81 case EVENT_RMT : /* Ring Man. */
82 rmt(smc,(int)ev->event) ;
83 break ;
84 case EVENT_SMT :
85 smt_event(smc,(int)ev->event) ;
86 break ;
87 #ifdef CONCENTRATOR
88 case 99 :
89 timer_test_event(smc,(int)ev->event) ;
90 break ;
91 #endif
92 case EVENT_PCMA : /* PHY A */
93 case EVENT_PCMB : /* PHY B */
94 default :
95 if (class >= EVENT_PCMA &&
96 class < EVENT_PCMA + NUMPHYS) {
97 pcm(smc,class - EVENT_PCMA,(int)ev->event) ;
98 break ;
99 }
100 SMT_PANIC(smc,SMT_E0121, SMT_E0121_MSG) ;
101 return ;
102 }
103
104 if (++ev == &smc->q.ev_queue[MAX_EVENT])
105 ev = smc->q.ev_queue ;
106
107 /* Renew get: it is used in queue_events to detect overruns */
108 smc->q.ev_get = ev;
109 }
110 }
111
112 /*
113 * smt_online connects to or disconnects from the ring
114 * MUST be called to initiate connection establishment
115 *
116 * on 0 disconnect
117 * on 1 connect
118 */
smt_online(struct s_smc * smc,int on)119 u_short smt_online(struct s_smc *smc, int on)
120 {
121 queue_event(smc,EVENT_ECM,on ? EC_CONNECT : EC_DISCONNECT) ;
122 ev_dispatcher(smc) ;
123 return smc->mib.fddiSMTCF_State;
124 }
125
126 /*
127 * set SMT flag to value
128 * flag flag name
129 * value flag value
130 * dump current flag setting
131 */
132 #ifdef CONCENTRATOR
do_smt_flag(struct s_smc * smc,char * flag,int value)133 void do_smt_flag(struct s_smc *smc, char *flag, int value)
134 {
135 #ifdef DEBUG
136 struct smt_debug *deb;
137
138 SK_UNUSED(smc) ;
139
140 #ifdef DEBUG_BRD
141 deb = &smc->debug;
142 #else
143 deb = &debug;
144 #endif
145 if (!strcmp(flag,"smt"))
146 deb->d_smt = value ;
147 else if (!strcmp(flag,"smtf"))
148 deb->d_smtf = value ;
149 else if (!strcmp(flag,"pcm"))
150 deb->d_pcm = value ;
151 else if (!strcmp(flag,"rmt"))
152 deb->d_rmt = value ;
153 else if (!strcmp(flag,"cfm"))
154 deb->d_cfm = value ;
155 else if (!strcmp(flag,"ecm"))
156 deb->d_ecm = value ;
157 printf("smt %d\n",deb->d_smt) ;
158 printf("smtf %d\n",deb->d_smtf) ;
159 printf("pcm %d\n",deb->d_pcm) ;
160 printf("rmt %d\n",deb->d_rmt) ;
161 printf("cfm %d\n",deb->d_cfm) ;
162 printf("ecm %d\n",deb->d_ecm) ;
163 #endif /* DEBUG */
164 }
165 #endif
166