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/iSeries_pci.h>
42 * Size of Bus VPD data
44 #define BUS_VPDSIZE 1024
48 #define VpdEndOfDataTag 0x78
49 #define VpdEndOfAreaTag 0x79
50 #define VpdIdStringTag 0x82
51 #define VpdVendorAreaTag 0x84
55 #define VpdFruFlag 0x4647 // "FG"
56 #define VpdFruFrameId 0x4649 // "FI"
57 #define VpdSlotMapFormat 0x4D46 // "MF"
58 #define VpdAsmPartNumber 0x504E // "PN"
59 #define VpdFruSerial 0x534E // "SN"
60 #define VpdSlotMap 0x534D // "SM"
63 * Structures of the areas
65 struct MfgVpdAreaStruct {
71 typedef struct MfgVpdAreaStruct MfgArea;
72 #define MFG_ENTRY_SIZE 3
74 struct SlotMapStruct {
82 typedef struct SlotMapStruct SlotMap;
83 #define SLOT_ENTRY_SIZE 16
86 * Formats the device information.
87 * - Pass in pci_dev* pointer to the device.
88 * - Pass in buffer to place the data. Danger here is the buffer must
89 * be as big as the client says it is. Should be at least 128 bytes.
90 * Return will the length of the string data put in the buffer.
92 * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet
95 int iSeries_Device_Information(struct pci_dev *PciDev, char *buffer,
98 struct iSeries_Device_Node *DevNode =
99 (struct iSeries_Device_Node *)PciDev->sysdata;
103 return sprintf(buffer,
104 "PCI: iSeries_Device_Information DevNode is NULL");
106 if (BufferSize < 128)
109 len = sprintf(buffer, "PCI: Bus%3d, Device%3d, Vendor %04X ",
110 ISERIES_BUS(DevNode), PCI_SLOT(PciDev->devfn),
112 len += sprintf(buffer + len, "Frame%3d, Card %4s ",
113 DevNode->FrameId, DevNode->CardLocation);
115 if (pci_class_name(PciDev->class >> 8) == 0)
116 len += sprintf(buffer + len, "0x%04X ",
117 (int)(PciDev->class >> 8));
119 len += sprintf(buffer + len, "%s",
120 pci_class_name(PciDev->class >> 8));
126 * Parse the Slot Area
128 void iSeries_Parse_SlotArea(SlotMap *MapPtr, int MapLen,
129 struct iSeries_Device_Node *DevNode)
131 int SlotMapLen = MapLen;
132 SlotMap *SlotMapPtr = MapPtr;
135 * Parse Slot label until we find the one requrested
137 while (SlotMapLen > 0) {
138 if (SlotMapPtr->AgentId == DevNode->AgentId ) {
140 * If Phb wasn't found, grab the entry first one found.
142 if (DevNode->PhbId == 0xff)
143 DevNode->PhbId = SlotMapPtr->PhbId;
144 /* Found it, extract the data. */
145 if (SlotMapPtr->PhbId == DevNode->PhbId ) {
146 memcpy(&DevNode->CardLocation,
147 &SlotMapPtr->CardLocation, 3);
148 DevNode->CardLocation[3] = 0;
152 /* Point to the next Slot */
153 SlotMapPtr = (SlotMap *)((char *)SlotMapPtr + SLOT_ENTRY_SIZE);
154 SlotMapLen -= SLOT_ENTRY_SIZE;
161 static void iSeries_Parse_MfgArea(u8 *AreaData, int AreaLen,
162 struct iSeries_Device_Node *DevNode)
164 MfgArea *MfgAreaPtr = (MfgArea *)AreaData;
165 int MfgAreaLen = AreaLen;
169 while (MfgAreaLen > 0) {
170 int MfgTagLen = MfgAreaPtr->TagLength;
171 /* Frame ID (FI 4649020310 ) */
172 if (MfgAreaPtr->Tag == VpdFruFrameId) /* FI */
173 DevNode->FrameId = MfgAreaPtr->AreaData1;
174 /* Slot Map Format (MF 4D46020004 ) */
175 else if (MfgAreaPtr->Tag == VpdSlotMapFormat) /* MF */
176 SlotMapFmt = (MfgAreaPtr->AreaData1 * 256)
177 + MfgAreaPtr->AreaData2;
178 /* Slot Map (SM 534D90 */
179 else if (MfgAreaPtr->Tag == VpdSlotMap) { /* SM */
182 if (SlotMapFmt == 0x1004)
183 SlotMapPtr = (SlotMap *)((char *)MfgAreaPtr
184 + MFG_ENTRY_SIZE + 1);
186 SlotMapPtr = (SlotMap *)((char *)MfgAreaPtr
188 iSeries_Parse_SlotArea(SlotMapPtr, MfgTagLen, DevNode);
191 * Point to the next Mfg Area
192 * Use defined size, sizeof give wrong answer
194 MfgAreaPtr = (MfgArea *)((char *)MfgAreaPtr + MfgTagLen
196 MfgAreaLen -= (MfgTagLen + MFG_ENTRY_SIZE);
201 * Look for "BUS".. Data is not Null terminated.
202 * PHBID of 0xFF indicates PHB was not found in VPD Data.
204 static int iSeries_Parse_PhbId(u8 *AreaPtr, int AreaLength)
206 u8 *PhbPtr = AreaPtr;
207 int DataLen = AreaLength;
210 while (DataLen > 0) {
211 if ((*PhbPtr == 'B') && (*(PhbPtr + 1) == 'U')
212 && (*(PhbPtr + 2) == 'S')) {
214 while (*PhbPtr == ' ')
216 PhbId = (*PhbPtr & 0x0F);
226 * Parse out the VPD Areas
228 static void iSeries_Parse_Vpd(u8 *VpdData, int VpdDataLen,
229 struct iSeries_Device_Node *DevNode)
231 u8 *TagPtr = VpdData;
232 int DataLen = VpdDataLen - 3;
234 while ((*TagPtr != VpdEndOfAreaTag) && (DataLen > 0)) {
235 int AreaLen = *(TagPtr + 1) + (*(TagPtr + 2) * 256);
236 u8 *AreaData = TagPtr + 3;
238 if (*TagPtr == VpdIdStringTag)
239 DevNode->PhbId = iSeries_Parse_PhbId(AreaData, AreaLen);
240 else if (*TagPtr == VpdVendorAreaTag)
241 iSeries_Parse_MfgArea(AreaData, AreaLen, DevNode);
242 /* Point to next Area. */
243 TagPtr = AreaData + AreaLen;
248 void iSeries_Get_Location_Code(struct iSeries_Device_Node *DevNode)
251 u8 *BusVpdPtr = (u8 *)kmalloc(BUS_VPDSIZE, GFP_KERNEL);
253 if (BusVpdPtr == NULL) {
254 printk("PCI: Bus VPD Buffer allocation failure.\n");
257 BusVpdLen = HvCallPci_getBusVpd(ISERIES_BUS(DevNode),
258 ISERIES_HV_ADDR(BusVpdPtr),
260 if (BusVpdLen == 0) {
262 printk("PCI: Bus VPD Buffer zero length.\n");
265 /* printk("PCI: BusVpdPtr: %p, %d\n",BusVpdPtr, BusVpdLen); */
266 /* Make sure this is what I think it is */
267 if (*BusVpdPtr != VpdIdStringTag) { /* 0x82 */
268 printk("PCI: Bus VPD Buffer missing starting tag.\n");
272 iSeries_Parse_Vpd(BusVpdPtr,BusVpdLen, DevNode);
273 sprintf(DevNode->Location, "Frame%3d, Card %-4s", DevNode->FrameId,
274 DevNode->CardLocation);