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