509e12de9783824bab3d698116f0338aaf755fd5
[linux-flexiantxendom0-3.2.10.git] / drivers / net / sk98lin / h / skvpd.h
1 /******************************************************************************
2  *
3  * Name:        skvpd.h
4  * Project:     GEnesis, PCI Gigabit Ethernet Adapter
5  * Version:     $Revision: 1.9 $
6  * Date:        $Date: 1999/11/22 14:02:27 $
7  * Purpose:     Defines and Macros for VPD handling
8  *
9  ******************************************************************************/
10
11 /******************************************************************************
12  *
13  *      (C)Copyright 1998,1999 SysKonnect,
14  *      a business unit of Schneider & Koch & Co. Datensysteme GmbH.
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  * History:
28  *
29  *      $Log: skvpd.h,v $
30  *      Revision 1.9  1999/11/22 14:02:27  cgoos
31  *      Changed license header to GPL.
32  *      
33  *      Revision 1.8  1999/03/11 14:26:40  malthoff
34  *      Replace __STDC__ with SK_KR_PROTO.
35  *      
36  *      Revision 1.7  1998/10/28 07:27:17  gklug
37  *      rmv: SWAP macros
38  *      add: VPD_IN/OUT8 macros
39  *      chg: interface definition
40  *      
41  *      Revision 1.6  1998/10/22 10:03:44  gklug
42  *      fix: use SK_OUT16 instead of SK_OUTW
43  *      
44  *      Revision 1.5  1998/10/14 07:05:31  cgoos
45  *      Changed constants in SK_SWAP_32 to UL.
46  *      
47  *      Revision 1.4  1998/08/19 08:14:09  gklug
48  *      fix: remove struct keyword as much as possible from the c-code (see CCC)
49  *      
50  *      Revision 1.3  1998/08/18 08:18:56  malthoff
51  *      Modify VPD in and out macros for SK_DIAG
52  *      
53  *      Revision 1.2  1998/07/03 14:49:08  malthoff
54  *      Add VPD_INxx() and VPD_OUTxx() macros for the Diagnostics tool.
55  *      
56  *      Revision 1.1  1998/06/19 14:08:03  malthoff
57  *      Created.
58  *      
59  *
60  ******************************************************************************/
61
62 /*
63  * skvpd.h      contains Diagnostic specific defines for VPD handling
64  */
65
66 #ifndef __INC_SKVPD_H_
67 #define __INC_SKVPD_H_
68
69 /*
70  * Define Resource Type Identifiers and VPD keywords
71  */
72 #define RES_ID          0x82    /* Resource Type ID String (Product Name) */
73 #define RES_VPD_R       0x90    /* start of VPD read only area */
74 #define RES_VPD_W       0x91    /* start of VPD read/write area */
75 #define RES_END         0x78    /* Resource Type End Tag */
76
77 #ifndef VPD_NAME
78 #define VPD_NAME        "Name"  /* Product Name, VPD name of RES_ID */
79 #endif  /* VPD_NAME */
80 #define VPD_PN          "PN"    /* Adapter Part Number */
81 #define VPD_EC          "EC"    /* Adapter Engineering Level */
82 #define VPD_MN          "MN"    /* Manufacture ID */
83 #define VPD_SN          "SN"    /* Serial Number */
84 #define VPD_CP          "CP"    /* Extended Capability */
85 #define VPD_RV          "RV"    /* Checksum and Reserved */
86 #define VPD_YA          "YA"    /* Asset Tag Identifier */
87 #define VPD_VL          "VL"    /* First Error Log Message (SK specific) */
88 #define VPD_VF          "VF"    /* Second Error Log Message (SK specific) */
89 #define VPD_RW          "RW"    /* Remaining Read / Write Area */
90
91 /* 'type' values for vpd_setup_para() */
92 #define VPD_RO_KEY      1       /* RO keys are "PN", "EC", "MN", "SN", "RV" */
93 #define VPD_RW_KEY      2       /* RW keys are "Yx", "Vx", and "RW" */
94
95 /* 'op' values for vpd_setup_para() */
96 #define ADD_KEY         1       /* add the key at the pos "RV" or "RW" */
97 #define OWR_KEY         2       /* overwrite key if already exists */
98
99 /*
100  * Define READ and WRITE Constants.
101  */
102 #define VPD_SIZE        512
103 #define VPD_READ        0x0000
104 #define VPD_WRITE       0x8000
105
106 #define VPD_STOP(pAC,IoC)       VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG,VPD_WRITE)
107
108 #define VPD_GET_RES_LEN(p)      ((unsigned int) \
109                                         (* (SK_U8 *)&(p)[1]) |\
110                                         ((* (SK_U8 *)&(p)[2]) << 8))
111 #define VPD_GET_VPD_LEN(p)      ((unsigned int)(* (SK_U8 *)&(p)[2]))
112 #define VPD_GET_VAL(p)          ((char *)&(p)[3])
113
114 #define VPD_MAX_LEN     50
115
116 /* VPD status */
117         /* bit 7..1 reserved */
118 #define VPD_VALID       (1<<0)          /* VPD data buffer, vpd_free_ro, */
119                                         /* and vpd_free_rw valid         */
120
121 /*
122  * VPD structs
123  */
124 typedef struct s_vpd_status {
125         unsigned short  vpd_status ;    /* VPD status, description see above */
126         int             vpd_free_ro ;   /* unused bytes in read only area */
127         int             vpd_free_rw ;   /* bytes available in read/write area */
128 } SK_VPD_STATUS;
129
130 typedef struct s_vpd {
131         SK_VPD_STATUS   v ;                     /* VPD status structure */
132         char            vpd_buf[VPD_SIZE] ;     /* VPD buffer */
133 } SK_VPD;
134
135 typedef struct s_vpd_para {
136         unsigned int    p_len ;         /* parameter length */
137         char            *p_val ;        /* points to the value */
138 } SK_VPD_PARA;
139
140 /*
141  * structure of Large Resource Type Identifiers
142  */
143 /* was removed, because of alignment problems */
144
145 /*
146  * sturcture of VPD keywords
147  */
148 typedef struct s_vpd_key {
149         char            p_key[2] ;      /* 2 bytes ID string */
150         unsigned char   p_len ;         /* 1 byte length */
151         char            p_val ;         /* start of the value string */
152 } SK_VPD_KEY;
153
154
155 /*
156  * System specific VPD macros
157  */
158 #ifndef SKDIAG
159 #ifndef VPD_DO_IO
160 #define VPD_OUT8(pAC,IoC,Addr,Val)      (void)SkPciWriteCfgByte(pAC,Addr,Val)
161 #define VPD_OUT16(pAC,IoC,Addr,Val)     (void)SkPciWriteCfgWord(pAC,Addr,Val)
162 #define VPD_OUT32(pAC,IoC,Addr,Val)     (void)SkPciWriteCfgDWord(pAC,Addr,Val)
163 #define VPD_IN8(pAC,IoC,Addr,pVal)      (void)SkPciReadCfgByte(pAC,Addr,pVal)
164 #define VPD_IN16(pAC,IoC,Addr,pVal)     (void)SkPciReadCfgWord(pAC,Addr,pVal)
165 #define VPD_IN32(pAC,IoC,Addr,pVal)     (void)SkPciReadCfgDWord(pAC,Addr,pVal)
166 #else   /* VPD_DO_IO */
167 #define VPD_OUT8(pAC,IoC,Addr,Val)      SK_OUT8(IoC,PCI_C(Addr),Val)
168 #define VPD_OUT16(pAC,IoC,Addr,Val)     SK_OUT16(IoC,PCI_C(Addr),Val)
169 #define VPD_OUT32(pAC,IoC,Addr,Val)     SK_OUT32(IoC,PCI_C(Addr),Val)
170 #define VPD_IN8(pAC,IoC,Addr,pVal)      SK_IN8(IoC,PCI_C(Addr),pVal)
171 #define VPD_IN16(pAC,IoC,Addr,pVal)     SK_IN16(IoC,PCI_C(Addr),pVal)
172 #define VPD_IN32(pAC,IoC,Addr,pVal)     SK_IN32(IoC,PCI_C(Addr),pVal)
173 #endif  /* VPD_DO_IO */
174 #else   /* SKDIAG */
175 #define VPD_OUT8(pAC,Ioc,Addr,Val) {                            \
176                 if ((pAC)->DgT.DgUseCfgCycle)                   \
177                         SkPciWriteCfgByte(pAC,Addr,Val) ;       \
178                 else                                            \
179                         SK_OUT8(pAC,PCI_C(Addr),Val);           \
180                 }
181 #define VPD_OUT16(pAC,Ioc,Addr,Val) {                           \
182                 if ((pAC)->DgT.DgUseCfgCycle)                   \
183                         SkPciWriteCfgWord(pAC,Addr,Val) ;       \
184                 else                                            \
185                         SK_OUT16(pAC,PCI_C(Addr),Val);          \
186                 }
187 #define VPD_OUT32(pAC,Ioc,Addr,Val) {                           \
188                 if ((pAC)->DgT.DgUseCfgCycle)                   \
189                         SkPciWriteCfgDWord(pAC,Addr,Val) ;      \
190                 else                                            \
191                         SK_OUT32(pAC,PCI_C(Addr),Val);          \
192                 }
193 #define VPD_IN8(pAC,Ioc,Addr,pVal) {                            \
194                 if ((pAC)->DgT.DgUseCfgCycle)                   \
195                         SkPciReadCfgByte(pAC,Addr,pVal) ;       \
196                 else                                            \
197                         SK_IN8(pAC,PCI_C(Addr),pVal);           \
198                 }
199 #define VPD_IN16(pAC,Ioc,Addr,pVal) {                           \
200                 if ((pAC)->DgT.DgUseCfgCycle)                   \
201                         SkPciReadCfgWord(pAC,Addr,pVal) ;       \
202                 else                                            \
203                         SK_IN16(pAC,PCI_C(Addr),pVal);          \
204                 }
205 #define VPD_IN32(pAC,Ioc,Addr,pVal) {                           \
206                 if ((pAC)->DgT.DgUseCfgCycle)                   \
207                         SkPciReadCfgDWord(pAC,Addr,pVal) ;      \
208                 else                                            \
209                         SK_IN32(pAC,PCI_C(Addr),pVal);          \
210                 }
211 #endif  /* nSKDIAG */
212
213 /* function prototypes ********************************************************/
214
215 #ifndef SK_KR_PROTO
216 extern SK_U32   VpdReadDWord(
217         SK_AC           *pAC,
218         SK_IOC          IoC,
219         int             addr) ;
220
221 extern int      VpdSetupPara(
222         SK_AC           *pAC,
223         char            *key,
224         char            *buf,
225         int             len,
226         int             type,
227         int             op) ;
228
229 extern SK_VPD_STATUS    *VpdStat(
230         SK_AC           *pAC,
231         SK_IOC          IoC) ;
232
233 extern int      VpdKeys(
234         SK_AC           *pAC,
235         SK_IOC          IoC,
236         char            *buf,
237         int             *len,
238         int             *elements) ;
239
240 extern int      VpdRead(
241         SK_AC           *pAC,
242         SK_IOC          IoC,
243         char            *key,
244         char            *buf,
245         int             *len) ;
246
247 extern  SK_BOOL VpdMayWrite(
248         char            *key) ;
249
250 extern int      VpdWrite(
251         SK_AC           *pAC,
252         SK_IOC          IoC,
253         char            *key,
254         char            *buf) ;
255
256 extern int      VpdDelete(
257         SK_AC           *pAC,
258         SK_IOC          IoC,
259         char            *key) ;
260
261 extern int      VpdUpdate(
262         SK_AC           *pAC,
263         SK_IOC          IoC);
264
265 extern void     VpdErrLog(
266         SK_AC           *pAC,
267         SK_IOC          IoC,
268         char            *msg) ;
269
270 #ifdef  SKDIAG
271 extern int      VpdReadBlock(
272         SK_AC           *pAC,
273         SK_IOC          IoC,
274         char            *buf,
275         int             addr,
276         int             len) ;
277
278 extern int      VpdWriteBlock(
279         SK_AC           *pAC,
280         SK_IOC          IoC,
281         char            *buf,
282         int             addr,
283         int             len) ;
284 #endif  /* SKDIAG */
285 #else   /* SK_KR_PROTO */
286 extern SK_U32   VpdReadDWord() ;
287 extern int      VpdSetupPara() ;
288 extern SK_VPD_STATUS    *VpdStat() ;
289 extern int      VpdKeys() ;
290 extern int      VpdRead() ;
291 extern SK_BOOL  VpdMayWrite() ;
292 extern int      VpdWrite() ;
293 extern int      VpdDelete() ;
294 extern int      VpdUpdate() ;
295 extern void     VpdErrLog() ;
296 #endif  /* SK_KR_PROTO */
297
298 #endif  /* __INC_SKVPD_H_ */