1/******************************************************************************
2 *
3 * Name:	skrlmt.h
4 * Project:	GEnesis, PCI Gigabit Ethernet Adapter
5 * Version:	$Revision: 1.1.1.1 $
6 * Date:	$Date: 2007/08/03 18:52:48 $
7 * Purpose:	Header file for Redundant Link ManagemenT.
8 *
9 ******************************************************************************/
10
11/******************************************************************************
12 *
13 *	(C)Copyright 1998-2002 SysKonnect GmbH.
14 *	(C)Copyright 2002-2003 Marvell.
15 *
16 *	This program is free software; you can redistribute it and/or modify
17 *	it under the terms of the GNU General Public License as published by
18 *	the Free Software Foundation; either version 2 of the License, or
19 *	(at your option) any later version.
20 *
21 *	The information in this file is provided "AS IS" without warranty.
22 *
23 ******************************************************************************/
24
25/******************************************************************************
26 *
27 * Description:
28 *
29 * This is the header file for Redundant Link ManagemenT.
30 *
31 * Include File Hierarchy:
32 *
33 *	"skdrv1st.h"
34 *	...
35 *	"sktypes.h"
36 *	"skqueue.h"
37 *	"skaddr.h"
38 *	"skrlmt.h"
39 *	...
40 *	"skdrv2nd.h"
41 *
42 ******************************************************************************/
43
44#ifndef __INC_SKRLMT_H
45#define __INC_SKRLMT_H
46
47#ifdef __cplusplus
48extern "C" {
49#endif	/* cplusplus */
50
51/* defines ********************************************************************/
52
53#define	SK_RLMT_NET_DOWN_TEMP	1	/* NET_DOWN due to last port down. */
54#define	SK_RLMT_NET_DOWN_FINAL	2	/* NET_DOWN due to RLMT_STOP. */
55
56/* ----- Default queue sizes - must be multiples of 8 KB ----- */
57
58/* Less than 8 KB free in RX queue => pause frames. */
59#define SK_RLMT_STANDBY_QRXSIZE	128	/* Size of rx standby queue in KB. */
60#define SK_RLMT_STANDBY_QXASIZE	32	/* Size of async standby queue in KB. */
61#define SK_RLMT_STANDBY_QXSSIZE	0	/* Size of sync standby queue in KB. */
62
63#define SK_RLMT_MAX_TX_BUF_SIZE	60	/* Maximum RLMT transmit size. */
64
65/* ----- PORT states ----- */
66
67#define SK_RLMT_PS_INIT			0	/* Port state: Init. */
68#define SK_RLMT_PS_LINK_DOWN	1	/* Port state: Link down. */
69#define SK_RLMT_PS_DOWN			2	/* Port state: Port down. */
70#define SK_RLMT_PS_GOING_UP		3	/* Port state: Going up. */
71#define SK_RLMT_PS_UP			4	/* Port state: Up. */
72
73/* ----- RLMT states ----- */
74
75#define SK_RLMT_RS_INIT			0	/* RLMT state: Init. */
76#define SK_RLMT_RS_NET_DOWN		1	/* RLMT state: Net down. */
77#define SK_RLMT_RS_NET_UP		2	/* RLMT state: Net up. */
78
79/* ----- PORT events ----- */
80
81#define SK_RLMT_LINK_UP			1001	/* Link came up. */
82#define SK_RLMT_LINK_DOWN		1002	/* Link went down. */
83#define SK_RLMT_PORT_ADDR		1003	/* Port address changed. */
84
85/* ----- RLMT events ----- */
86
87#define SK_RLMT_START			2001	/* Start RLMT. */
88#define SK_RLMT_STOP			2002	/* Stop RLMT. */
89#define SK_RLMT_PACKET_RECEIVED	2003	/* Packet was received for RLMT. */
90#define SK_RLMT_STATS_CLEAR		2004	/* Clear statistics. */
91#define SK_RLMT_STATS_UPDATE	2005	/* Update statistics. */
92#define SK_RLMT_PREFPORT_CHANGE	2006	/* Change preferred port. */
93#define SK_RLMT_MODE_CHANGE		2007	/* New RlmtMode. */
94#define SK_RLMT_SET_NETS		2008	/* Number of Nets (1 or 2). */
95
96/* ----- RLMT mode bits ----- */
97
98/*
99 * CAUTION:	These defines are private to RLMT.
100 *			Please use the RLMT mode defines below.
101 */
102
103#define SK_RLMT_CHECK_LINK		  1		/* Check Link. */
104#define SK_RLMT_CHECK_LOC_LINK	  2		/* Check other link on same adapter. */
105#define SK_RLMT_CHECK_SEG		  4		/* Check segmentation. */
106
107#ifndef RLMT_CHECK_REMOTE
108#define SK_RLMT_CHECK_OTHERS	SK_RLMT_CHECK_LOC_LINK
109#else	/* RLMT_CHECK_REMOTE */
110#define SK_RLMT_CHECK_REM_LINK	  8		/* Check link(s) on other adapter(s). */
111#define SK_RLMT_MAX_REMOTE_PORTS_CHECKED	3
112#define SK_RLMT_CHECK_OTHERS	\
113		(SK_RLMT_CHECK_LOC_LINK | SK_RLMT_CHECK_REM_LINK)
114#endif	/* RLMT_CHECK_REMOTE */
115
116#ifndef SK_RLMT_ENABLE_TRANSPARENT
117#define SK_RLMT_TRANSPARENT		  0		/* RLMT transparent - inactive. */
118#else	/* SK_RLMT_ENABLE_TRANSPARENT */
119#define SK_RLMT_TRANSPARENT		128		/* RLMT transparent. */
120#endif	/* SK_RLMT_ENABLE_TRANSPARENT */
121
122/* ----- RLMT modes ----- */
123
124/* Check Link State. */
125#define SK_RLMT_MODE_CLS	(SK_RLMT_CHECK_LINK)
126
127/* Check Local Ports: check other links on the same adapter. */
128#define SK_RLMT_MODE_CLP	(SK_RLMT_CHECK_LINK | SK_RLMT_CHECK_LOC_LINK)
129
130/* Check Local Ports and Segmentation Status. */
131#define SK_RLMT_MODE_CLPSS	\
132		(SK_RLMT_CHECK_LINK | SK_RLMT_CHECK_LOC_LINK | SK_RLMT_CHECK_SEG)
133
134#ifdef RLMT_CHECK_REMOTE
135/* Check Local and Remote Ports: check links (local or remote). */
136	Name of define TBD!
137#define SK_RLMT_MODE_CRP	\
138		(SK_RLMT_CHECK_LINK | SK_RLMT_CHECK_LOC_LINK | SK_RLMT_CHECK_REM_LINK)
139
140/* Check Local and Remote Ports and Segmentation Status. */
141	Name of define TBD!
142#define SK_RLMT_MODE_CRPSS	\
143		(SK_RLMT_CHECK_LINK | SK_RLMT_CHECK_LOC_LINK | \
144		SK_RLMT_CHECK_REM_LINK | SK_RLMT_CHECK_SEG)
145#endif	/* RLMT_CHECK_REMOTE */
146
147/* ----- RLMT lookahead result bits ----- */
148
149#define SK_RLMT_RX_RLMT			1	/* Give packet to RLMT. */
150#define SK_RLMT_RX_PROTOCOL		2	/* Give packet to protocol. */
151
152/* Macros */
153
154
155#define SK_RLMT_PRE_LOOKAHEAD(pAC,PortNum,PktLen,IsBc,pOffset,pNumBytes) { \
156	SK_AC	*_pAC; \
157	SK_U32	_PortNum; \
158	_pAC = (pAC); \
159	_PortNum = (SK_U32)(PortNum); \
160	/* _pAC->Rlmt.Port[_PortNum].PacketsRx++; */ \
161	_pAC->Rlmt.Port[_PortNum].PacketsPerTimeSlot++; \
162    if (_pAC->Rlmt.RlmtOff) { \
163		*(pNumBytes) = 0; \
164    } \
165    else {\
166        if ((_pAC->Rlmt.Port[_PortNum].Net->RlmtMode & SK_RLMT_TRANSPARENT) != 0) { \
167    		*(pNumBytes) = 0; \
168    	} \
169    	else if (IsBc) { \
170    		if (_pAC->Rlmt.Port[_PortNum].Net->RlmtMode != SK_RLMT_MODE_CLS) { \
171    			*(pNumBytes) = 6; \
172    			*(pOffset) = 6; \
173    		} \
174    		else { \
175    			*(pNumBytes) = 0; \
176    		} \
177    	} \
178    	else { \
179    		if ((PktLen) > SK_RLMT_MAX_TX_BUF_SIZE) { \
180    			/* _pAC->Rlmt.Port[_PortNum].DataPacketsPerTimeSlot++; */ \
181    			*(pNumBytes) = 0; \
182    		} \
183    		else { \
184    			*(pNumBytes) = 6; \
185    			*(pOffset) = 0; \
186    		} \
187    	} \
188    } \
189}
190
191
192#define SK_RLMT_LOOKAHEAD(pAC,PortNum,pLaPacket,IsBc,IsMc,pForRlmt) { \
193	SK_AC	*_pAC; \
194	SK_U32	_PortNum; \
195	SK_U8	*_pLaPacket; \
196	_pAC = (pAC); \
197	_PortNum = (SK_U32)(PortNum); \
198	_pLaPacket = (SK_U8 *)(pLaPacket); \
199	if (IsBc) {\
200		if (!SK_ADDR_EQUAL(_pLaPacket, _pAC->Addr.Net[_pAC->Rlmt.Port[ \
201			_PortNum].Net->NetNumber].CurrentMacAddress.a)) { \
202			_pAC->Rlmt.Port[_PortNum].BcTimeStamp = SkOsGetTime(_pAC); \
203			_pAC->Rlmt.CheckSwitch = SK_TRUE; \
204		} \
205		/* _pAC->Rlmt.Port[_PortNum].DataPacketsPerTimeSlot++; */ \
206		*(pForRlmt) = SK_RLMT_RX_PROTOCOL; \
207	} \
208	else if (IsMc) { \
209		if (SK_ADDR_EQUAL(_pLaPacket, BridgeMcAddr.a)) { \
210			_pAC->Rlmt.Port[_PortNum].BpduPacketsPerTimeSlot++; \
211			if (_pAC->Rlmt.Port[_PortNum].Net->RlmtMode & SK_RLMT_CHECK_SEG) { \
212				*(pForRlmt) = SK_RLMT_RX_RLMT | SK_RLMT_RX_PROTOCOL; \
213			} \
214			else { \
215				*(pForRlmt) = SK_RLMT_RX_PROTOCOL; \
216			} \
217		} \
218		else if (SK_ADDR_EQUAL(_pLaPacket, SkRlmtMcAddr.a)) { \
219			*(pForRlmt) = SK_RLMT_RX_RLMT; \
220		} \
221		else { \
222			/* _pAC->Rlmt.Port[_PortNum].DataPacketsPerTimeSlot++; */ \
223			*(pForRlmt) = SK_RLMT_RX_PROTOCOL; \
224		} \
225	} \
226	else { \
227		if (SK_ADDR_EQUAL( \
228			_pLaPacket, \
229			_pAC->Addr.Port[_PortNum].CurrentMacAddress.a)) { \
230			*(pForRlmt) = SK_RLMT_RX_RLMT; \
231		} \
232		else { \
233			/* _pAC->Rlmt.Port[_PortNum].DataPacketsPerTimeSlot++; */ \
234			*(pForRlmt) = SK_RLMT_RX_PROTOCOL; \
235		} \
236	} \
237}
238
239#ifdef SK_RLMT_FAST_LOOKAHEAD
240Error: SK_RLMT_FAST_LOOKAHEAD no longer used. Use new macros for lookahead.
241#endif	/* SK_RLMT_FAST_LOOKAHEAD */
242#ifdef SK_RLMT_SLOW_LOOKAHEAD
243Error: SK_RLMT_SLOW_LOOKAHEAD no longer used. Use new macros for lookahead.
244#endif	/* SK_RLMT_SLOW_LOOKAHEAD */
245
246/* typedefs *******************************************************************/
247
248#ifdef SK_RLMT_MBUF_PRIVATE
249typedef struct s_RlmtMbuf {
250	some content
251} SK_RLMT_MBUF;
252#endif	/* SK_RLMT_MBUF_PRIVATE */
253
254
255#ifdef SK_LA_INFO
256typedef struct s_Rlmt_PacketInfo {
257	unsigned	PacketLength;			/* Length of packet. */
258	unsigned	PacketType;				/* Directed/Multicast/Broadcast. */
259} SK_RLMT_PINFO;
260#endif	/* SK_LA_INFO */
261
262
263typedef struct s_RootId {
264	SK_U8		Id[8];					/* Root Bridge Id. */
265} SK_RLMT_ROOT_ID;
266
267
268typedef struct s_port {
269	SK_MAC_ADDR	CheckAddr;
270	SK_BOOL		SuspectTx;
271} SK_PORT_CHECK;
272
273
274typedef struct s_RlmtNet SK_RLMT_NET;
275
276
277typedef struct s_RlmtPort {
278
279/* ----- Public part (read-only) ----- */
280
281	SK_U8			PortState;				/* Current state of this port. */
282
283	/* For PNMI */
284	SK_BOOL			LinkDown;
285	SK_BOOL			PortDown;
286	SK_U8			Align01;
287
288	SK_U32			PortNumber;				/* Number of port on adapter. */
289	SK_RLMT_NET *	Net;					/* Net port belongs to. */
290
291	SK_U64			TxHelloCts;
292	SK_U64			RxHelloCts;
293	SK_U64			TxSpHelloReqCts;
294	SK_U64			RxSpHelloCts;
295
296/* ----- Private part ----- */
297
298/*	SK_U64			PacketsRx; */				/* Total packets received. */
299	SK_U32			PacketsPerTimeSlot;		/* Packets rxed between TOs. */
300/*	SK_U32			DataPacketsPerTimeSlot; */	/* Data packets ... */
301	SK_U32			BpduPacketsPerTimeSlot;	/* BPDU packets rxed in TS. */
302	SK_U64			BcTimeStamp;			/* Time of last BC receive. */
303	SK_U64			GuTimeStamp;			/* Time of entering GOING_UP. */
304
305	SK_TIMER		UpTimer;				/* Timer struct Link/Port up. */
306	SK_TIMER		DownRxTimer;			/* Timer struct down rx. */
307	SK_TIMER		DownTxTimer;			/* Timer struct down tx. */
308
309	SK_U32			CheckingState;			/* Checking State. */
310
311	SK_ADDR_PORT *	AddrPort;
312
313	SK_U8			Random[4];				/* Random value. */
314	unsigned		PortsChecked;			/* #ports checked. */
315	unsigned		PortsSuspect;			/* #ports checked that are s. */
316	SK_PORT_CHECK	PortCheck[1];
317/*	SK_PORT_CHECK	PortCheck[SK_MAX_MACS - 1]; */
318
319	SK_BOOL			PortStarted;			/* Port is started. */
320	SK_BOOL			PortNoRx;				/* NoRx for >= 1 time slot. */
321	SK_BOOL			RootIdSet;
322	SK_RLMT_ROOT_ID	Root;					/* Root Bridge Id. */
323} SK_RLMT_PORT;
324
325
326struct s_RlmtNet {
327
328/* ----- Public part (read-only) ----- */
329
330	SK_U32			NetNumber;			/* Number of net. */
331
332	SK_RLMT_PORT *	Port[SK_MAX_MACS];	/* Ports that belong to this net. */
333	SK_U32			NumPorts;			/* Number of ports. */
334	SK_U32			PrefPort;			/* Preferred port. */
335
336	/* For PNMI */
337
338	SK_U32			ChgBcPrio;			/* Change Priority of last broadcast received */
339	SK_U32			RlmtMode;			/* Check ... */
340	SK_U32			ActivePort;			/* Active port. */
341	SK_U32			Preference;		/* 0xFFFFFFFF: Automatic. */
342
343	SK_U8			RlmtState;			/* Current RLMT state. */
344
345/* ----- Private part ----- */
346	SK_BOOL			RootIdSet;
347	SK_U16			Align01;
348
349	int				LinksUp;			/* #Links up. */
350	int				PortsUp;			/* #Ports up. */
351	SK_U32			TimeoutValue;		/* RLMT timeout value. */
352
353	SK_U32			CheckingState;		/* Checking State. */
354	SK_RLMT_ROOT_ID	Root;				/* Root Bridge Id. */
355
356	SK_TIMER		LocTimer;			/* Timer struct. */
357	SK_TIMER		SegTimer;			/* Timer struct. */
358};
359
360
361typedef struct s_Rlmt {
362
363/* ----- Public part (read-only) ----- */
364
365	SK_U32			NumNets;			/* Number of nets. */
366	SK_U32			NetsStarted;		/* Number of nets started. */
367	SK_RLMT_NET		Net[SK_MAX_NETS];	/* Array of available nets. */
368	SK_RLMT_PORT	Port[SK_MAX_MACS];	/* Array of available ports. */
369
370/* ----- Private part ----- */
371	SK_BOOL			CheckSwitch;
372	SK_BOOL			RlmtOff;            /* set to zero if the Mac addresses
373                                           are equal or the second one
374                                           is zero */
375	SK_U16			Align01;
376
377} SK_RLMT;
378
379
380extern	SK_MAC_ADDR	BridgeMcAddr;
381extern	SK_MAC_ADDR	SkRlmtMcAddr;
382
383/* function prototypes ********************************************************/
384
385
386#ifndef SK_KR_PROTO
387
388/* Functions provided by SkRlmt */
389
390/* ANSI/C++ compliant function prototypes */
391
392extern	void	SkRlmtInit(
393	SK_AC	*pAC,
394	SK_IOC	IoC,
395	int		Level);
396
397extern	int	SkRlmtEvent(
398	SK_AC		*pAC,
399	SK_IOC		IoC,
400	SK_U32		Event,
401	SK_EVPARA	Para);
402
403#else	/* defined(SK_KR_PROTO) */
404
405/* Non-ANSI/C++ compliant function prototypes */
406
407#error KR-style function prototypes are not yet provided.
408
409#endif	/* defined(SK_KR_PROTO)) */
410
411
412#ifdef __cplusplus
413}
414#endif	/* __cplusplus */
415
416#endif	/* __INC_SKRLMT_H */
417