aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/fddi/skfp/srf.c
blob: cc27dea3414e89163e2cb53dd6540fc258ad091c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
/******************************************************************************
 *
 *	(C)Copyright 1998,1999 SysKonnect,
 *	a business unit of Schneider & Koch & Co. Datensysteme GmbH.
 *
 *	See the file "skfddi.c" for further information.
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *
 *	The information in this file is provided "AS IS" without warranty.
 *
 ******************************************************************************/

/*
	SMT 7.2 Status Response Frame Implementation
	SRF state machine and frame generation
*/

#include "h/types.h"
#include "h/fddi.h"
#include "h/smc.h"
#include "h/smt_p.h"

#define KERNEL
#include "h/smtstate.h"

#ifndef	SLIM_SMT
#ifndef	BOOT

#ifndef	lint
static const char ID_sccs[] = "@(#)srf.c	1.18 97/08/04 (C) SK " ;
#endif


/*
 * function declarations
 */
static void clear_all_rep(struct s_smc *smc);
static void clear_reported(struct s_smc *smc);
static void smt_send_srf(struct s_smc *smc);
static struct s_srf_evc *smt_get_evc(struct s_smc *smc, int code, int index);

#define MAX_EVCS	ARRAY_SIZE(smc->evcs)

struct evc_init {
	u_char code ;
	u_char index ;
	u_char n ;
	u_short	para ;
}  ;

static const struct evc_init evc_inits[] = {
	{ SMT_COND_SMT_PEER_WRAP,		0,1,SMT_P1048	} ,

	{ SMT_COND_MAC_DUP_ADDR,		INDEX_MAC, NUMMACS,SMT_P208C } ,
	{ SMT_COND_MAC_FRAME_ERROR,		INDEX_MAC, NUMMACS,SMT_P208D } ,
	{ SMT_COND_MAC_NOT_COPIED,		INDEX_MAC, NUMMACS,SMT_P208E } ,
	{ SMT_EVENT_MAC_NEIGHBOR_CHANGE,	INDEX_MAC, NUMMACS,SMT_P208F } ,
	{ SMT_EVENT_MAC_PATH_CHANGE,		INDEX_MAC, NUMMACS,SMT_P2090 } ,

	{ SMT_COND_PORT_LER,			INDEX_PORT,NUMPHYS,SMT_P4050 } ,
	{ SMT_COND_PORT_EB_ERROR,		INDEX_PORT,NUMPHYS,SMT_P4052 } ,
	{ SMT_EVENT_PORT_CONNECTION,		INDEX_PORT,NUMPHYS,SMT_P4051 } ,
	{ SMT_EVENT_PORT_PATH_CHANGE,		INDEX_PORT,NUMPHYS,SMT_P4053 } ,
} ;

#define MAX_INIT_EVC	ARRAY_SIZE(evc_inits)

void smt_init_evc(struct s_smc *smc)
{
	struct s_srf_evc	*evc ;
	const struct evc_init 	*init ;
	unsigned int		i ;
	int			index ;
	int			offset ;

	static u_char		fail_safe = FALSE ;

	memset((char *)smc->evcs,0,sizeof(smc->evcs)) ;

	evc = smc->evcs ;
	init = evc_inits ;

	for (i = 0 ; i < MAX_INIT_EVC ; i++) {
		for (index = 0 ; index < init->n ; index++) {
			evc->evc_code = init->code ;
			evc->evc_para = init->para ;
			evc->evc_index = init->index + index ;
#ifndef	DEBUG
			evc->evc_multiple = &fail_safe ;
			evc->evc_cond_state = &fail_safe ;
#endif
			evc++ ;
		}
		init++ ;
	}

	if ((unsigned int) (evc - smc->evcs) > MAX_EVCS) {
		SMT_PANIC(smc,SMT_E0127, SMT_E0127_MSG) ;
	}

	/*
	 * conditions
	 */
	smc->evcs[0].evc_cond_state = &smc->mib.fddiSMTPeerWrapFlag ;
	smc->evcs[1].evc_cond_state =
		&smc->mib.m[MAC0].fddiMACDuplicateAddressCond ;
	smc->evcs[2].evc_cond_state =
		&smc->mib.m[MAC0].fddiMACFrameErrorFlag ;
	smc->evcs[3].evc_cond_state =
		&smc->mib.m[MAC0].fddiMACNotCopiedFlag ;

	/*
	 * events
	 */
	smc->evcs[4].evc_multiple = &smc->mib.m[MAC0].fddiMACMultiple_N ;
	smc->evcs[5].evc_multiple = &smc->mib.m[MAC0].fddiMACMultiple_P ;

	offset = 6 ;
	for (i = 0 ; i < NUMPHYS ; i++) {
		/*
		 * conditions
		 */
		smc->evcs[offset + 0*NUMPHYS].evc_cond_state =
			&smc->mib.p[i].fddiPORTLerFlag ;
		smc->evcs[offset + 1*NUMPHYS].evc_cond_state =
			&smc->mib.p[i].fddiPORTEB_Condition ;

		/*
		 * events
		 */
		smc->evcs[offset + 2*NUMPHYS].evc_multiple =
			&smc->mib.p[i].fddiPORTMultiple_U ;
		smc->evcs[offset + 3*NUMPHYS].evc_multiple =
			&smc->mib.p[i].fddiPORTMultiple_P ;
		offset++ ;
	}
#ifdef	DEBUG
	for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
		if (SMT_IS_CONDITION(evc->evc_code)) {
			if (!evc->evc_cond_state) {
				SMT_PANIC(smc,SMT_E0128, SMT_E0128_MSG) ;
			}
			evc->evc_multiple = &fail_safe ;
		}
		else {
			if (!evc->evc_multiple) {
				SMT_PANIC(smc,SMT_E0129, SMT_E0129_MSG) ;
			}
			evc->evc_cond_state = &fail_safe ;
		}
	}
#endif
	smc->srf.TSR = smt_get_time() ;
	smc->srf.sr_state = SR0_WAIT ;
}

static struct s_srf_evc *smt_get_evc(struct s_smc *smc, int code, int index)
{
	unsigned int		i ;
	struct s_srf_evc	*evc ;

	for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
		if (evc->evc_code == code && evc->evc_index == index)
			return evc;
	}
	return NULL;
}

#define THRESHOLD_2	(2*TICKS_PER_SECOND)
#define THRESHOLD_32	(32*TICKS_PER_SECOND)

#ifdef	DEBUG
static const char * const srf_names[] = {
	"None","MACPathChangeEvent",	"MACNeighborChangeEvent",
	"PORTPathChangeEvent",		"PORTUndesiredConnectionAttemptEvent",
	"SMTPeerWrapCondition",		"SMTHoldCondition",
	"MACFrameErrorCondition",	"MACDuplicateAddressCondition",
	"MACNotCopiedCondition",	"PORTEBErrorCondition",
	"PORTLerCondition"
} ;
#endif

void smt_srf_event(struct s_smc *smc, int code, int index, int cond)
{
	struct s_srf_evc	*evc ;
	int			cond_asserted = 0 ;
	int			cond_deasserted = 0 ;
	int			event_occurred = 0 ;
	int			tsr ;
	int			T_Limit = 2*TICKS_PER_SECOND ;

	if (code == SMT_COND_MAC_DUP_ADDR && cond) {
		RS_SET(smc,RS_DUPADDR) ;
	}

	if (code) {
		DB_SMT("SRF: %s index %d\n",srf_names[code],index) ;

		if (!(evc = smt_get_evc(smc,code,index))) {
			DB_SMT("SRF : smt_get_evc() failed\n",0,0) ;
			return ;
		}
		/*
		 * ignore condition if no change
		 */
		if (SMT_IS_CONDITION(code)) {
			if (*evc->evc_cond_state == cond)
				return ;
		}

		/*
		 * set transition time stamp
		 */
		smt_set_timestamp(smc,smc->mib.fddiSMTTransitionTimeStamp) ;
		if (SMT_IS_CONDITION(code)) {
			DB_SMT("SRF: condition is %s\n",cond ? "ON":"OFF",0) ;
			if (cond) {
				*evc->evc_cond_state = TRUE ;
				evc->evc_rep_required = TRUE ;
				smc->srf.any_report = TRUE ;
				cond_asserted = TRUE ;
			}
			else {
				*evc->evc_cond_state = FALSE ;
				cond_deasserted = TRUE ;
			}
		}
		else {
			if (evc->evc_rep_required) {
				*evc->evc_multiple  = TRUE ;
			}
			else {
				evc->evc_rep_required = TRUE ;
				*evc->evc_multiple  = FALSE ;
			}
			smc->srf.any_report = TRUE ;
			event_occurred = TRUE ;
		}
#ifdef	FDDI_MIB
		snmp_srf_event(smc,evc) ;
#endif	/* FDDI_MIB */
	}
	tsr = smt_get_time() - smc->srf.TSR ;

	switch (smc->srf.sr_state) {
	case SR0_WAIT :
		/* SR01a */
		if (cond_asserted && tsr < T_Limit) {
			smc->srf.SRThreshold = THRESHOLD_2 ;
			smc->srf.sr_state = SR1_HOLDOFF ;
			break ;
		}
		/* SR01b */
		if (cond_deasserted && tsr < T_Limit) {
			smc->srf.sr_state = SR1_HOLDOFF ;
			break ;
		}
		/* SR01c */
		if (event_occurred && tsr < T_Limit) {
			smc->srf.sr_state = SR1_HOLDOFF ;
			break ;
		}
		/* SR00b */
		if (cond_asserted && tsr >= T_Limit) {
			smc->srf.SRThreshold = THRESHOLD_2 ;
			smc->srf.TSR = smt_get_time() ;
			smt_send_srf(smc) ;
			break ;
		}
		/* SR00c */
		if (cond_deasserted && tsr >= T_Limit) {
			smc->srf.TSR = smt_get_time() ;
			smt_send_srf(smc) ;
			break ;
		}
		/* SR00d */
		if (event_occurred && tsr >= T_Limit) {
			smc->srf.TSR = smt_get_time() ;
			smt_send_srf(smc) ;
			break ;
		}
		/* SR00e */
		if (smc->srf.any_report && (u_long) tsr >=
			smc->srf.SRThreshold) {
			smc->srf.SRThreshold *= 2 ;
			if (smc->srf.SRThreshold > THRESHOLD_32)
				smc->srf.SRThreshold = THRESHOLD_32 ;
			smc->srf.TSR = smt_get_time() ;
			smt_send_srf(smc) ;
			break ;
		}
		/* SR02 */
		if (!smc->mib.fddiSMTStatRptPolicy) {
			smc->srf.sr_state = SR2_DISABLED ;
			break ;
		}
		break ;
	case SR1_HOLDOFF :
		/* SR10b */
		if (tsr >= T_Limit) {
			smc->srf.sr_state = SR0_WAIT ;
			smc->srf.TSR = smt_get_time() ;
			smt_send_srf(smc) ;
			break ;
		}
		/* SR11a */
		if (cond_asserted) {
			smc->srf.SRThreshold = THRESHOLD_2 ;
		}
		/* SR11b */
		/* SR11c */
		/* handled above */
		/* SR12 */
		if (!smc->mib.fddiSMTStatRptPolicy) {
			smc->srf.sr_state = SR2_DISABLED ;
			break ;
		}
		break ;
	case SR2_DISABLED :
		if (smc->mib.fddiSMTStatRptPolicy) {
			smc->srf.sr_state = SR0_WAIT ;
			smc->srf.TSR = smt_get_time() ;
			smc->srf.SRThreshold = THRESHOLD_2 ;
			clear_all_rep(smc) ;
			break ;
		}
		break ;
	}
}

static void clear_all_rep(struct s_smc *smc)
{
	struct s_srf_evc	*evc ;
	unsigned int		i ;

	for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
		evc->evc_rep_required = FALSE ;
		if (SMT_IS_CONDITION(evc->evc_code))
			*evc->evc_cond_state = FALSE ;
	}
	smc->srf.any_report = FALSE ;
}

static void clear_reported(struct s_smc *smc)
{
	struct s_srf_evc	*evc ;
	unsigned int		i ;

	smc->srf.any_report = FALSE ;
	for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
		if (SMT_IS_CONDITION(evc->evc_code)) {
			if (*evc->evc_cond_state == FALSE)
				evc->evc_rep_required = FALSE ;
			else
				smc->srf.any_report = TRUE ;
		}
		else {
			evc->evc_rep_required = FALSE ;
			*evc->evc_multiple = FALSE ;
		}
	}
}

/*
 * build and send SMT SRF frame
 */
static void smt_send_srf(struct s_smc *smc)
{

	struct smt_header	*smt ;
	struct s_srf_evc	*evc ;
	SK_LOC_DECL(struct s_pcon,pcon) ;
	SMbuf			*mb ;
	unsigned int		i ;

	static const struct fddi_addr SMT_SRF_DA = {
		{ 0x80, 0x01, 0x43, 0x00, 0x80, 0x08 }
	} ;

	/*
	 * build SMT header
	 */
	if (!smc->r.sm_ma_avail)
		return ;
	if (!(mb = smt_build_frame(smc,SMT_SRF,SMT_ANNOUNCE,0)))
		return ;

	RS_SET(smc,RS_SOFTERROR) ;

	smt = smtod(mb, struct smt_header *) ;
	smt->smt_dest = SMT_SRF_DA ;		/* DA == SRF multicast */

	/*
	 * setup parameter status
	 */
	pcon.pc_len = SMT_MAX_INFO_LEN ;	/* max para length */
	pcon.pc_err = 0 ;			/* no error */
	pcon.pc_badset = 0 ;			/* no bad set count */
	pcon.pc_p = (void *) (smt + 1) ;	/* paras start here */

	smt_add_para(smc,&pcon,(u_short) SMT_P1033,0,0) ;
	smt_add_para(smc,&pcon,(u_short) SMT_P1034,0,0) ;

	for (i = 0, evc = smc->evcs ; i < MAX_EVCS ; i++, evc++) {
		if (evc->evc_rep_required) {
			smt_add_para(smc,&pcon,evc->evc_para,
				(int)evc->evc_index,0) ;
		}
	}
	smt->smt_len = SMT_MAX_INFO_LEN - pcon.pc_len ;
	mb->sm_len = smt->smt_len + sizeof(struct smt_header) ;

	DB_SMT("SRF: sending SRF at %x, len %d\n",smt,mb->sm_len) ;
	DB_SMT("SRF: state SR%d Threshold %d\n",
		smc->srf.sr_state,smc->srf.SRThreshold/TICKS_PER_SECOND) ;
#ifdef	DEBUG
	dump_smt(smc,smt,"SRF Send") ;
#endif
	smt_send_frame(smc,mb,FC_SMT_INFO,0) ;
	clear_reported(smc) ;
}

#endif	/* no BOOT */
#endif	/* no SLIM_SMT */