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