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