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