1 /******************************************************************************
2  *
3  * Name:	skvpd.h
4  * Project:	GEnesis, PCI Gigabit Ethernet Adapter
5  * Purpose:	Defines and Macros for VPD handling
6  *
7  ******************************************************************************/
8 
9 /******************************************************************************
10  *
11  *	(C)Copyright 1998-2003 SysKonnect GmbH.
12  *
13  *	This program is free software; you can redistribute it and/or modify
14  *	it under the terms of the GNU General Public License as published by
15  *	the Free Software Foundation; either version 2 of the License, or
16  *	(at your option) any later version.
17  *
18  *	The information in this file is provided "AS IS" without warranty.
19  *
20  ******************************************************************************/
21 
22 /*
23  * skvpd.h	contains Diagnostic specific defines for VPD handling
24  */
25 
26 #ifndef __INC_SKVPD_H_
27 #define __INC_SKVPD_H_
28 
29 /*
30  * Define Resource Type Identifiers and VPD keywords
31  */
32 #define	RES_ID		0x82	/* Resource Type ID String (Product Name) */
33 #define RES_VPD_R	0x90	/* start of VPD read only area */
34 #define RES_VPD_W	0x91	/* start of VPD read/write area */
35 #define RES_END		0x78	/* Resource Type End Tag */
36 
37 #ifndef VPD_NAME
38 #define VPD_NAME	"Name"	/* Product Name, VPD name of RES_ID */
39 #endif	/* VPD_NAME */
40 #define VPD_PN		"PN"	/* Adapter Part Number */
41 #define	VPD_EC		"EC"	/* Adapter Engineering Level */
42 #define VPD_MN		"MN"	/* Manufacture ID */
43 #define VPD_SN		"SN"	/* Serial Number */
44 #define VPD_CP		"CP"	/* Extended Capability */
45 #define VPD_RV		"RV"	/* Checksum and Reserved */
46 #define	VPD_YA		"YA"	/* Asset Tag Identifier */
47 #define VPD_VL		"VL"	/* First Error Log Message (SK specific) */
48 #define VPD_VF		"VF"	/* Second Error Log Message (SK specific) */
49 #define VPD_RW		"RW"	/* Remaining Read / Write Area */
50 
51 /* 'type' values for vpd_setup_para() */
52 #define VPD_RO_KEY	1	/* RO keys are "PN", "EC", "MN", "SN", "RV" */
53 #define VPD_RW_KEY	2	/* RW keys are "Yx", "Vx", and "RW" */
54 
55 /* 'op' values for vpd_setup_para() */
56 #define	ADD_KEY		1	/* add the key at the pos "RV" or "RW" */
57 #define OWR_KEY		2	/* overwrite key if already exists */
58 
59 /*
60  * Define READ and WRITE Constants.
61  */
62 
63 #define VPD_DEV_ID_GENESIS 	0x4300
64 
65 #define	VPD_SIZE_YUKON		256
66 #define	VPD_SIZE_GENESIS	512
67 #define	VPD_SIZE			512
68 #define VPD_READ	0x0000
69 #define VPD_WRITE	0x8000
70 
71 #define VPD_STOP(pAC,IoC)	VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG,VPD_WRITE)
72 
73 #define VPD_GET_RES_LEN(p)	((unsigned int) \
74 					(* (SK_U8 *)&(p)[1]) |\
75 					((* (SK_U8 *)&(p)[2]) << 8))
76 #define VPD_GET_VPD_LEN(p)	((unsigned int)(* (SK_U8 *)&(p)[2]))
77 #define VPD_GET_VAL(p)		((char *)&(p)[3])
78 
79 #define VPD_MAX_LEN	50
80 
81 /* VPD status */
82 	/* bit 7..1 reserved */
83 #define VPD_VALID	(1<<0)	/* VPD data buffer, vpd_free_ro, */
84 							/* and vpd_free_rw valid	 */
85 
86 /*
87  * VPD structs
88  */
89 typedef	struct s_vpd_status {
90 	unsigned short	Align01;			/* Alignment */
91 	unsigned short	vpd_status;			/* VPD status, description see above */
92 	int				vpd_free_ro;		/* unused bytes in read only area */
93 	int				vpd_free_rw;		/* bytes available in read/write area */
94 } SK_VPD_STATUS;
95 
96 typedef	struct s_vpd {
97 	SK_VPD_STATUS	v;					/* VPD status structure */
98 	char			vpd_buf[VPD_SIZE];	/* VPD buffer */
99 	int				rom_size;			/* VPD ROM Size from PCI_OUR_REG_2 */
100 	int				vpd_size;			/* saved VPD-size */
101 } SK_VPD;
102 
103 typedef	struct s_vpd_para {
104 	unsigned int	p_len;	/* parameter length */
105 	char			*p_val;	/* points to the value */
106 } SK_VPD_PARA;
107 
108 /*
109  * structure of Large Resource Type Identifiers
110  */
111 
112 /* was removed because of alignment problems */
113 
114 /*
115  * structure of VPD keywords
116  */
117 typedef	struct s_vpd_key {
118 	char			p_key[2];	/* 2 bytes ID string */
119 	unsigned char	p_len;		/* 1 byte length */
120 	char			p_val;		/* start of the value string */
121 } SK_VPD_KEY;
122 
123 
124 /*
125  * System specific VPD macros
126  */
127 #ifndef SKDIAG
128 #ifndef VPD_DO_IO
129 #define VPD_OUT8(pAC,IoC,Addr,Val)	(void)SkPciWriteCfgByte(pAC,Addr,Val)
130 #define VPD_OUT16(pAC,IoC,Addr,Val)	(void)SkPciWriteCfgWord(pAC,Addr,Val)
131 #define VPD_OUT32(pAC,IoC,Addr,Val)	(void)SkPciWriteCfgDWord(pAC,Addr,Val)
132 #define VPD_IN8(pAC,IoC,Addr,pVal)	(void)SkPciReadCfgByte(pAC,Addr,pVal)
133 #define VPD_IN16(pAC,IoC,Addr,pVal)	(void)SkPciReadCfgWord(pAC,Addr,pVal)
134 #define VPD_IN32(pAC,IoC,Addr,pVal)	(void)SkPciReadCfgDWord(pAC,Addr,pVal)
135 #else	/* VPD_DO_IO */
136 #define VPD_OUT8(pAC,IoC,Addr,Val)	SK_OUT8(IoC,PCI_C(Addr),Val)
137 #define VPD_OUT16(pAC,IoC,Addr,Val)	SK_OUT16(IoC,PCI_C(Addr),Val)
138 #define VPD_OUT32(pAC,IoC,Addr,Val)	SK_OUT32(IoC,PCI_C(Addr),Val)
139 #define VPD_IN8(pAC,IoC,Addr,pVal)	SK_IN8(IoC,PCI_C(Addr),pVal)
140 #define VPD_IN16(pAC,IoC,Addr,pVal)	SK_IN16(IoC,PCI_C(Addr),pVal)
141 #define VPD_IN32(pAC,IoC,Addr,pVal)	SK_IN32(IoC,PCI_C(Addr),pVal)
142 #endif	/* VPD_DO_IO */
143 #else	/* SKDIAG */
144 #define VPD_OUT8(pAC,Ioc,Addr,Val) {			\
145 		if ((pAC)->DgT.DgUseCfgCycle)			\
146 			SkPciWriteCfgByte(pAC,Addr,Val);	\
147 		else									\
148 			SK_OUT8(pAC,PCI_C(Addr),Val);		\
149 		}
150 #define VPD_OUT16(pAC,Ioc,Addr,Val) {			\
151 		if ((pAC)->DgT.DgUseCfgCycle)			\
152 			SkPciWriteCfgWord(pAC,Addr,Val);	\
153 		else						\
154 			SK_OUT16(pAC,PCI_C(Addr),Val);		\
155 		}
156 #define VPD_OUT32(pAC,Ioc,Addr,Val) {			\
157 		if ((pAC)->DgT.DgUseCfgCycle)			\
158 			SkPciWriteCfgDWord(pAC,Addr,Val);	\
159 		else						\
160 			SK_OUT32(pAC,PCI_C(Addr),Val); 		\
161 		}
162 #define VPD_IN8(pAC,Ioc,Addr,pVal) {			\
163 		if ((pAC)->DgT.DgUseCfgCycle) 			\
164 			SkPciReadCfgByte(pAC,Addr,pVal);	\
165 		else						\
166 			SK_IN8(pAC,PCI_C(Addr),pVal); 		\
167 		}
168 #define VPD_IN16(pAC,Ioc,Addr,pVal) {			\
169 		if ((pAC)->DgT.DgUseCfgCycle) 			\
170 			SkPciReadCfgWord(pAC,Addr,pVal);	\
171 		else						\
172 			SK_IN16(pAC,PCI_C(Addr),pVal); 		\
173 		}
174 #define VPD_IN32(pAC,Ioc,Addr,pVal) {			\
175 		if ((pAC)->DgT.DgUseCfgCycle)			\
176 			SkPciReadCfgDWord(pAC,Addr,pVal);	\
177 		else						\
178 			SK_IN32(pAC,PCI_C(Addr),pVal);		\
179 		}
180 #endif	/* nSKDIAG */
181 
182 /* function prototypes ********************************************************/
183 
184 #ifndef	SK_KR_PROTO
185 #ifdef SKDIAG
186 extern SK_U32	VpdReadDWord(
187 	SK_AC		*pAC,
188 	SK_IOC		IoC,
189 	int			addr);
190 #endif	/* SKDIAG */
191 
192 extern int	VpdSetupPara(
193 	SK_AC		*pAC,
194 	const char	*key,
195 	const char	*buf,
196 	int			len,
197 	int			type,
198 	int			op);
199 
200 extern SK_VPD_STATUS	*VpdStat(
201 	SK_AC		*pAC,
202 	SK_IOC		IoC);
203 
204 extern int	VpdKeys(
205 	SK_AC		*pAC,
206 	SK_IOC		IoC,
207 	char		*buf,
208 	int			*len,
209 	int			*elements);
210 
211 extern int	VpdRead(
212 	SK_AC		*pAC,
213 	SK_IOC		IoC,
214 	const char	*key,
215 	char		*buf,
216 	int			*len);
217 
218 extern SK_BOOL	VpdMayWrite(
219 	char		*key);
220 
221 extern int	VpdWrite(
222 	SK_AC		*pAC,
223 	SK_IOC		IoC,
224 	const char	*key,
225 	const char	*buf);
226 
227 extern int	VpdDelete(
228 	SK_AC		*pAC,
229 	SK_IOC		IoC,
230 	char		*key);
231 
232 extern int	VpdUpdate(
233 	SK_AC		*pAC,
234 	SK_IOC		IoC);
235 
236 extern void	VpdErrLog(
237 	SK_AC		*pAC,
238 	SK_IOC		IoC,
239 	char		*msg);
240 
241 #ifdef	SKDIAG
242 extern int	VpdReadBlock(
243 	SK_AC		*pAC,
244 	SK_IOC		IoC,
245 	char		*buf,
246 	int			addr,
247 	int			len);
248 
249 extern int	VpdWriteBlock(
250 	SK_AC		*pAC,
251 	SK_IOC		IoC,
252 	char		*buf,
253 	int			addr,
254 	int			len);
255 #endif	/* SKDIAG */
256 #else	/* SK_KR_PROTO */
257 extern SK_U32	VpdReadDWord();
258 extern int	VpdSetupPara();
259 extern SK_VPD_STATUS	*VpdStat();
260 extern int	VpdKeys();
261 extern int	VpdRead();
262 extern SK_BOOL	VpdMayWrite();
263 extern int	VpdWrite();
264 extern int	VpdDelete();
265 extern int	VpdUpdate();
266 extern void	VpdErrLog();
267 #endif	/* SK_KR_PROTO */
268 
269 #endif	/* __INC_SKVPD_H_ */
270