1 /************************************************************************/
2 /* File iSeries_vpdInfo.c created by Allan Trautman on Fri Feb 2 2001. */
3 /************************************************************************/
4 /* This code gets the card location of the hardware */
5 /* Copyright (C) 20yy <Allan H Trautman> <IBM Corp> */
7 /* This program is free software; you can redistribute it and/or modify */
8 /* it under the terms of the GNU General Public License as published by */
9 /* the Free Software Foundation; either version 2 of the License, or */
10 /* (at your option) any later version. */
12 /* This program is distributed in the hope that it will be useful, */
13 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
15 /* GNU General Public License for more details. */
17 /* You should have received a copy of the GNU General Public License */
18 /* along with this program; if not, write to the: */
19 /* Free Software Foundation, Inc., */
20 /* 59 Temple Place, Suite 330, */
21 /* Boston, MA 02111-1307 USA */
22 /************************************************************************/
23 /* Change Activity: */
24 /* Created, Feb 2, 2001 */
25 /* Ported to ppc64, August 20, 2001 */
26 /* End Change Activity */
27 /************************************************************************/
28 #include <linux/config.h>
29 #include <linux/init.h>
30 #include <linux/module.h>
31 #include <linux/pci.h>
32 #include <asm/types.h>
33 #include <asm/resource.h>
35 #include <asm/iSeries/HvCallPci.h>
36 #include <asm/iSeries/HvTypes.h>
37 #include <asm/iSeries/mf.h>
38 #include <asm/iSeries/LparData.h>
39 #include <asm/iSeries/iSeries_pci.h>
43 * Size of Bus VPD data
45 #define BUS_VPDSIZE 1024
49 #define VpdEndOfDataTag 0x78
50 #define VpdEndOfAreaTag 0x79
51 #define VpdIdStringTag 0x82
52 #define VpdVendorAreaTag 0x84
56 #define VpdFruFlag 0x4647 // "FG"
57 #define VpdFruFrameId 0x4649 // "FI"
58 #define VpdSlotMapFormat 0x4D46 // "MF"
59 #define VpdAsmPartNumber 0x504E // "PN"
60 #define VpdFruSerial 0x534E // "SN"
61 #define VpdSlotMap 0x534D // "SM"
64 * Structures of the areas
66 struct MfgVpdAreaStruct
{
72 typedef struct MfgVpdAreaStruct MfgArea
;
73 #define MFG_ENTRY_SIZE 3
75 struct SlotMapStruct
{
83 typedef struct SlotMapStruct SlotMap
;
84 #define SLOT_ENTRY_SIZE 16
87 * Formats the device information.
88 * - Pass in pci_dev* pointer to the device.
89 * - Pass in buffer to place the data. Danger here is the buffer must
90 * be as big as the client says it is. Should be at least 128 bytes.
91 * Return will the length of the string data put in the buffer.
93 * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet
96 int iSeries_Device_Information(struct pci_dev
*PciDev
, char *buffer
,
99 struct iSeries_Device_Node
*DevNode
=
100 (struct iSeries_Device_Node
*)PciDev
->sysdata
;
104 return sprintf(buffer
,
105 "PCI: iSeries_Device_Information DevNode is NULL");
107 if (BufferSize
< 128)
110 len
= sprintf(buffer
, "PCI: Bus%3d, Device%3d, Vendor %04X ",
111 ISERIES_BUS(DevNode
), PCI_SLOT(PciDev
->devfn
),
113 len
+= sprintf(buffer
+ len
, "Frame%3d, Card %4s ",
114 DevNode
->FrameId
, DevNode
->CardLocation
);
116 if (pci_class_name(PciDev
->class >> 8) == 0)
117 len
+= sprintf(buffer
+ len
, "0x%04X ",
118 (int)(PciDev
->class >> 8));
120 len
+= sprintf(buffer
+ len
, "%s",
121 pci_class_name(PciDev
->class >> 8));
127 * Parse the Slot Area
129 void iSeries_Parse_SlotArea(SlotMap
*MapPtr
, int MapLen
,
130 struct iSeries_Device_Node
*DevNode
)
132 int SlotMapLen
= MapLen
;
133 SlotMap
*SlotMapPtr
= MapPtr
;
136 * Parse Slot label until we find the one requrested
138 while (SlotMapLen
> 0) {
139 if (SlotMapPtr
->AgentId
== DevNode
->AgentId
) {
141 * If Phb wasn't found, grab the entry first one found.
143 if (DevNode
->PhbId
== 0xff)
144 DevNode
->PhbId
= SlotMapPtr
->PhbId
;
145 /* Found it, extract the data. */
146 if (SlotMapPtr
->PhbId
== DevNode
->PhbId
) {
147 memcpy(&DevNode
->CardLocation
,
148 &SlotMapPtr
->CardLocation
, 3);
149 DevNode
->CardLocation
[3] = 0;
153 /* Point to the next Slot */
154 SlotMapPtr
= (SlotMap
*)((char *)SlotMapPtr
+ SLOT_ENTRY_SIZE
);
155 SlotMapLen
-= SLOT_ENTRY_SIZE
;
162 static void iSeries_Parse_MfgArea(u8
*AreaData
, int AreaLen
,
163 struct iSeries_Device_Node
*DevNode
)
165 MfgArea
*MfgAreaPtr
= (MfgArea
*)AreaData
;
166 int MfgAreaLen
= AreaLen
;
170 while (MfgAreaLen
> 0) {
171 int MfgTagLen
= MfgAreaPtr
->TagLength
;
172 /* Frame ID (FI 4649020310 ) */
173 if (MfgAreaPtr
->Tag
== VpdFruFrameId
) /* FI */
174 DevNode
->FrameId
= MfgAreaPtr
->AreaData1
;
175 /* Slot Map Format (MF 4D46020004 ) */
176 else if (MfgAreaPtr
->Tag
== VpdSlotMapFormat
) /* MF */
177 SlotMapFmt
= (MfgAreaPtr
->AreaData1
* 256)
178 + MfgAreaPtr
->AreaData2
;
179 /* Slot Map (SM 534D90 */
180 else if (MfgAreaPtr
->Tag
== VpdSlotMap
) { /* SM */
183 if (SlotMapFmt
== 0x1004)
184 SlotMapPtr
= (SlotMap
*)((char *)MfgAreaPtr
185 + MFG_ENTRY_SIZE
+ 1);
187 SlotMapPtr
= (SlotMap
*)((char *)MfgAreaPtr
189 iSeries_Parse_SlotArea(SlotMapPtr
, MfgTagLen
, DevNode
);
192 * Point to the next Mfg Area
193 * Use defined size, sizeof give wrong answer
195 MfgAreaPtr
= (MfgArea
*)((char *)MfgAreaPtr
+ MfgTagLen
197 MfgAreaLen
-= (MfgTagLen
+ MFG_ENTRY_SIZE
);
202 * Look for "BUS".. Data is not Null terminated.
203 * PHBID of 0xFF indicates PHB was not found in VPD Data.
205 static int iSeries_Parse_PhbId(u8
*AreaPtr
, int AreaLength
)
207 u8
*PhbPtr
= AreaPtr
;
208 int DataLen
= AreaLength
;
211 while (DataLen
> 0) {
212 if ((*PhbPtr
== 'B') && (*(PhbPtr
+ 1) == 'U')
213 && (*(PhbPtr
+ 2) == 'S')) {
215 while (*PhbPtr
== ' ')
217 PhbId
= (*PhbPtr
& 0x0F);
227 * Parse out the VPD Areas
229 static void iSeries_Parse_Vpd(u8
*VpdData
, int VpdDataLen
,
230 struct iSeries_Device_Node
*DevNode
)
232 u8
*TagPtr
= VpdData
;
233 int DataLen
= VpdDataLen
- 3;
235 while ((*TagPtr
!= VpdEndOfAreaTag
) && (DataLen
> 0)) {
236 int AreaLen
= *(TagPtr
+ 1) + (*(TagPtr
+ 2) * 256);
237 u8
*AreaData
= TagPtr
+ 3;
239 if (*TagPtr
== VpdIdStringTag
)
240 DevNode
->PhbId
= iSeries_Parse_PhbId(AreaData
, AreaLen
);
241 else if (*TagPtr
== VpdVendorAreaTag
)
242 iSeries_Parse_MfgArea(AreaData
, AreaLen
, DevNode
);
243 /* Point to next Area. */
244 TagPtr
= AreaData
+ AreaLen
;
249 void iSeries_Get_Location_Code(struct iSeries_Device_Node
*DevNode
)
252 u8
*BusVpdPtr
= (u8
*)kmalloc(BUS_VPDSIZE
, GFP_KERNEL
);
254 if (BusVpdPtr
== NULL
) {
255 printk("PCI: Bus VPD Buffer allocation failure.\n");
258 BusVpdLen
= HvCallPci_getBusVpd(ISERIES_BUS(DevNode
),
259 ISERIES_HV_ADDR(BusVpdPtr
),
261 if (BusVpdLen
== 0) {
263 printk("PCI: Bus VPD Buffer zero length.\n");
266 /* printk("PCI: BusVpdPtr: %p, %d\n",BusVpdPtr, BusVpdLen); */
267 /* Make sure this is what I think it is */
268 if (*BusVpdPtr
!= VpdIdStringTag
) { /* 0x82 */
269 printk("PCI: Bus VPD Buffer missing starting tag.\n");
273 iSeries_Parse_Vpd(BusVpdPtr
,BusVpdLen
, DevNode
);
274 sprintf(DevNode
->Location
, "Frame%3d, Card %-4s", DevNode
->FrameId
,
275 DevNode
->CardLocation
);