diff options
Diffstat (limited to 'arch/ppc64/kernel/iSeries_VpdInfo.c')
-rw-r--r-- | arch/ppc64/kernel/iSeries_VpdInfo.c | 220 |
1 files changed, 107 insertions, 113 deletions
diff --git a/arch/ppc64/kernel/iSeries_VpdInfo.c b/arch/ppc64/kernel/iSeries_VpdInfo.c index a6f0ff2d0239..d11c732daf81 100644 --- a/arch/ppc64/kernel/iSeries_VpdInfo.c +++ b/arch/ppc64/kernel/iSeries_VpdInfo.c | |||
@@ -1,31 +1,31 @@ | |||
1 | /************************************************************************/ | 1 | /* |
2 | /* File iSeries_vpdInfo.c created by Allan Trautman on Fri Feb 2 2001. */ | 2 | * File iSeries_vpdInfo.c created by Allan Trautman on Fri Feb 2 2001. |
3 | /************************************************************************/ | 3 | * |
4 | /* This code gets the card location of the hardware */ | 4 | * This code gets the card location of the hardware |
5 | /* Copyright (C) 20yy <Allan H Trautman> <IBM Corp> */ | 5 | * Copyright (C) 2001 <Allan H Trautman> <IBM Corp> |
6 | /* */ | 6 | * Copyright (C) 2005 Stephen Rothwel, IBM Corp |
7 | /* This program is free software; you can redistribute it and/or modify */ | 7 | * |
8 | /* it under the terms of the GNU General Public License as published by */ | 8 | * This program is free software; you can redistribute it and/or modify |
9 | /* the Free Software Foundation; either version 2 of the License, or */ | 9 | * it under the terms of the GNU General Public License as published by |
10 | /* (at your option) any later version. */ | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | /* */ | 11 | * (at your option) any later version. |
12 | /* This program is distributed in the hope that it will be useful, */ | 12 | * |
13 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | 13 | * This program is distributed in the hope that it will be useful, |
14 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | /* GNU General Public License for more details. */ | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | /* */ | 16 | * GNU General Public License for more details. |
17 | /* You should have received a copy of the GNU General Public License */ | 17 | * |
18 | /* along with this program; if not, write to the: */ | 18 | * You should have received a copy of the GNU General Public License |
19 | /* Free Software Foundation, Inc., */ | 19 | * along with this program; if not, write to the: |
20 | /* 59 Temple Place, Suite 330, */ | 20 | * Free Software Foundation, Inc., |
21 | /* Boston, MA 02111-1307 USA */ | 21 | * 59 Temple Place, Suite 330, |
22 | /************************************************************************/ | 22 | * Boston, MA 02111-1307 USA |
23 | /* Change Activity: */ | 23 | * |
24 | /* Created, Feb 2, 2001 */ | 24 | * Change Activity: |
25 | /* Ported to ppc64, August 20, 2001 */ | 25 | * Created, Feb 2, 2001 |
26 | /* End Change Activity */ | 26 | * Ported to ppc64, August 20, 2001 |
27 | /************************************************************************/ | 27 | * End Change Activity |
28 | #include <linux/config.h> | 28 | */ |
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/pci.h> | 31 | #include <linux/pci.h> |
@@ -34,30 +34,25 @@ | |||
34 | 34 | ||
35 | #include <asm/iSeries/HvCallPci.h> | 35 | #include <asm/iSeries/HvCallPci.h> |
36 | #include <asm/iSeries/HvTypes.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> | 37 | #include <asm/iSeries/iSeries_pci.h> |
40 | #include "pci.h" | ||
41 | 38 | ||
42 | /* | 39 | /* |
43 | * Size of Bus VPD data | 40 | * Size of Bus VPD data |
44 | */ | 41 | */ |
45 | #define BUS_VPDSIZE 1024 | 42 | #define BUS_VPDSIZE 1024 |
43 | |||
46 | /* | 44 | /* |
47 | * Bus Vpd Tags | 45 | * Bus Vpd Tags |
48 | */ | 46 | */ |
49 | #define VpdEndOfDataTag 0x78 | ||
50 | #define VpdEndOfAreaTag 0x79 | 47 | #define VpdEndOfAreaTag 0x79 |
51 | #define VpdIdStringTag 0x82 | 48 | #define VpdIdStringTag 0x82 |
52 | #define VpdVendorAreaTag 0x84 | 49 | #define VpdVendorAreaTag 0x84 |
50 | |||
53 | /* | 51 | /* |
54 | * Mfg Area Tags | 52 | * Mfg Area Tags |
55 | */ | 53 | */ |
56 | #define VpdFruFlag 0x4647 // "FG" | ||
57 | #define VpdFruFrameId 0x4649 // "FI" | 54 | #define VpdFruFrameId 0x4649 // "FI" |
58 | #define VpdSlotMapFormat 0x4D46 // "MF" | 55 | #define VpdSlotMapFormat 0x4D46 // "MF" |
59 | #define VpdAsmPartNumber 0x504E // "PN" | ||
60 | #define VpdFruSerial 0x534E // "SN" | ||
61 | #define VpdSlotMap 0x534D // "SM" | 56 | #define VpdSlotMap 0x534D // "SM" |
62 | 57 | ||
63 | /* | 58 | /* |
@@ -79,74 +74,33 @@ struct SlotMapStruct { | |||
79 | char CardLocation[3]; | 74 | char CardLocation[3]; |
80 | char Parms[8]; | 75 | char Parms[8]; |
81 | char Reserved[2]; | 76 | char Reserved[2]; |
82 | }; | 77 | }; |
83 | typedef struct SlotMapStruct SlotMap; | 78 | typedef struct SlotMapStruct SlotMap; |
84 | #define SLOT_ENTRY_SIZE 16 | 79 | #define SLOT_ENTRY_SIZE 16 |
85 | 80 | ||
86 | /* | 81 | /* |
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. | ||
92 | * Format: | ||
93 | * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet | ||
94 | * controller | ||
95 | */ | ||
96 | int iSeries_Device_Information(struct pci_dev *PciDev, char *buffer, | ||
97 | int BufferSize) | ||
98 | { | ||
99 | struct iSeries_Device_Node *DevNode = | ||
100 | (struct iSeries_Device_Node *)PciDev->sysdata; | ||
101 | int len; | ||
102 | |||
103 | if (DevNode == NULL) | ||
104 | return sprintf(buffer, | ||
105 | "PCI: iSeries_Device_Information DevNode is NULL"); | ||
106 | |||
107 | if (BufferSize < 128) | ||
108 | return 0; | ||
109 | |||
110 | len = sprintf(buffer, "PCI: Bus%3d, Device%3d, Vendor %04X ", | ||
111 | ISERIES_BUS(DevNode), PCI_SLOT(PciDev->devfn), | ||
112 | PciDev->vendor); | ||
113 | len += sprintf(buffer + len, "Frame%3d, Card %4s ", | ||
114 | DevNode->FrameId, DevNode->CardLocation); | ||
115 | #ifdef CONFIG_PCI | ||
116 | if (pci_class_name(PciDev->class >> 8) == 0) | ||
117 | len += sprintf(buffer + len, "0x%04X ", | ||
118 | (int)(PciDev->class >> 8)); | ||
119 | else | ||
120 | len += sprintf(buffer + len, "%s", | ||
121 | pci_class_name(PciDev->class >> 8)); | ||
122 | #endif | ||
123 | return len; | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * Parse the Slot Area | 82 | * Parse the Slot Area |
128 | */ | 83 | */ |
129 | void iSeries_Parse_SlotArea(SlotMap *MapPtr, int MapLen, | 84 | static void __init iSeries_Parse_SlotArea(SlotMap *MapPtr, int MapLen, |
130 | struct iSeries_Device_Node *DevNode) | 85 | HvAgentId agent, u8 *PhbId, char card[4]) |
131 | { | 86 | { |
132 | int SlotMapLen = MapLen; | 87 | int SlotMapLen = MapLen; |
133 | SlotMap *SlotMapPtr = MapPtr; | 88 | SlotMap *SlotMapPtr = MapPtr; |
134 | 89 | ||
135 | /* | 90 | /* |
136 | * Parse Slot label until we find the one requrested | 91 | * Parse Slot label until we find the one requested |
137 | */ | 92 | */ |
138 | while (SlotMapLen > 0) { | 93 | while (SlotMapLen > 0) { |
139 | if (SlotMapPtr->AgentId == DevNode->AgentId ) { | 94 | if (SlotMapPtr->AgentId == agent) { |
140 | /* | 95 | /* |
141 | * If Phb wasn't found, grab the entry first one found. | 96 | * If Phb wasn't found, grab the entry first one found. |
142 | */ | 97 | */ |
143 | if (DevNode->PhbId == 0xff) | 98 | if (*PhbId == 0xff) |
144 | DevNode->PhbId = SlotMapPtr->PhbId; | 99 | *PhbId = SlotMapPtr->PhbId; |
145 | /* Found it, extract the data. */ | 100 | /* Found it, extract the data. */ |
146 | if (SlotMapPtr->PhbId == DevNode->PhbId ) { | 101 | if (SlotMapPtr->PhbId == *PhbId) { |
147 | memcpy(&DevNode->CardLocation, | 102 | memcpy(card, &SlotMapPtr->CardLocation, 3); |
148 | &SlotMapPtr->CardLocation, 3); | 103 | card[3] = 0; |
149 | DevNode->CardLocation[3] = 0; | ||
150 | break; | 104 | break; |
151 | } | 105 | } |
152 | } | 106 | } |
@@ -159,8 +113,9 @@ void iSeries_Parse_SlotArea(SlotMap *MapPtr, int MapLen, | |||
159 | /* | 113 | /* |
160 | * Parse the Mfg Area | 114 | * Parse the Mfg Area |
161 | */ | 115 | */ |
162 | static void iSeries_Parse_MfgArea(u8 *AreaData, int AreaLen, | 116 | static void __init iSeries_Parse_MfgArea(u8 *AreaData, int AreaLen, |
163 | struct iSeries_Device_Node *DevNode) | 117 | HvAgentId agent, u8 *PhbId, |
118 | u8 *frame, char card[4]) | ||
164 | { | 119 | { |
165 | MfgArea *MfgAreaPtr = (MfgArea *)AreaData; | 120 | MfgArea *MfgAreaPtr = (MfgArea *)AreaData; |
166 | int MfgAreaLen = AreaLen; | 121 | int MfgAreaLen = AreaLen; |
@@ -171,7 +126,7 @@ static void iSeries_Parse_MfgArea(u8 *AreaData, int AreaLen, | |||
171 | int MfgTagLen = MfgAreaPtr->TagLength; | 126 | int MfgTagLen = MfgAreaPtr->TagLength; |
172 | /* Frame ID (FI 4649020310 ) */ | 127 | /* Frame ID (FI 4649020310 ) */ |
173 | if (MfgAreaPtr->Tag == VpdFruFrameId) /* FI */ | 128 | if (MfgAreaPtr->Tag == VpdFruFrameId) /* FI */ |
174 | DevNode->FrameId = MfgAreaPtr->AreaData1; | 129 | *frame = MfgAreaPtr->AreaData1; |
175 | /* Slot Map Format (MF 4D46020004 ) */ | 130 | /* Slot Map Format (MF 4D46020004 ) */ |
176 | else if (MfgAreaPtr->Tag == VpdSlotMapFormat) /* MF */ | 131 | else if (MfgAreaPtr->Tag == VpdSlotMapFormat) /* MF */ |
177 | SlotMapFmt = (MfgAreaPtr->AreaData1 * 256) | 132 | SlotMapFmt = (MfgAreaPtr->AreaData1 * 256) |
@@ -183,10 +138,11 @@ static void iSeries_Parse_MfgArea(u8 *AreaData, int AreaLen, | |||
183 | if (SlotMapFmt == 0x1004) | 138 | if (SlotMapFmt == 0x1004) |
184 | SlotMapPtr = (SlotMap *)((char *)MfgAreaPtr | 139 | SlotMapPtr = (SlotMap *)((char *)MfgAreaPtr |
185 | + MFG_ENTRY_SIZE + 1); | 140 | + MFG_ENTRY_SIZE + 1); |
186 | else | 141 | else |
187 | SlotMapPtr = (SlotMap *)((char *)MfgAreaPtr | 142 | SlotMapPtr = (SlotMap *)((char *)MfgAreaPtr |
188 | + MFG_ENTRY_SIZE); | 143 | + MFG_ENTRY_SIZE); |
189 | iSeries_Parse_SlotArea(SlotMapPtr, MfgTagLen, DevNode); | 144 | iSeries_Parse_SlotArea(SlotMapPtr, MfgTagLen, |
145 | agent, PhbId, card); | ||
190 | } | 146 | } |
191 | /* | 147 | /* |
192 | * Point to the next Mfg Area | 148 | * Point to the next Mfg Area |
@@ -194,19 +150,19 @@ static void iSeries_Parse_MfgArea(u8 *AreaData, int AreaLen, | |||
194 | */ | 150 | */ |
195 | MfgAreaPtr = (MfgArea *)((char *)MfgAreaPtr + MfgTagLen | 151 | MfgAreaPtr = (MfgArea *)((char *)MfgAreaPtr + MfgTagLen |
196 | + MFG_ENTRY_SIZE); | 152 | + MFG_ENTRY_SIZE); |
197 | MfgAreaLen -= (MfgTagLen + MFG_ENTRY_SIZE); | 153 | MfgAreaLen -= (MfgTagLen + MFG_ENTRY_SIZE); |
198 | } | 154 | } |
199 | } | 155 | } |
200 | 156 | ||
201 | /* | 157 | /* |
202 | * Look for "BUS".. Data is not Null terminated. | 158 | * Look for "BUS".. Data is not Null terminated. |
203 | * PHBID of 0xFF indicates PHB was not found in VPD Data. | 159 | * PHBID of 0xFF indicates PHB was not found in VPD Data. |
204 | */ | 160 | */ |
205 | static int iSeries_Parse_PhbId(u8 *AreaPtr, int AreaLength) | 161 | static int __init iSeries_Parse_PhbId(u8 *AreaPtr, int AreaLength) |
206 | { | 162 | { |
207 | u8 *PhbPtr = AreaPtr; | 163 | u8 *PhbPtr = AreaPtr; |
208 | int DataLen = AreaLength; | 164 | int DataLen = AreaLength; |
209 | char PhbId = 0xFF; | 165 | char PhbId = 0xFF; |
210 | 166 | ||
211 | while (DataLen > 0) { | 167 | while (DataLen > 0) { |
212 | if ((*PhbPtr == 'B') && (*(PhbPtr + 1) == 'U') | 168 | if ((*PhbPtr == 'B') && (*(PhbPtr + 1) == 'U') |
@@ -216,7 +172,7 @@ static int iSeries_Parse_PhbId(u8 *AreaPtr, int AreaLength) | |||
216 | ++PhbPtr; | 172 | ++PhbPtr; |
217 | PhbId = (*PhbPtr & 0x0F); | 173 | PhbId = (*PhbPtr & 0x0F); |
218 | break; | 174 | break; |
219 | } | 175 | } |
220 | ++PhbPtr; | 176 | ++PhbPtr; |
221 | --DataLen; | 177 | --DataLen; |
222 | } | 178 | } |
@@ -226,52 +182,90 @@ static int iSeries_Parse_PhbId(u8 *AreaPtr, int AreaLength) | |||
226 | /* | 182 | /* |
227 | * Parse out the VPD Areas | 183 | * Parse out the VPD Areas |
228 | */ | 184 | */ |
229 | static void iSeries_Parse_Vpd(u8 *VpdData, int VpdDataLen, | 185 | static void __init iSeries_Parse_Vpd(u8 *VpdData, int VpdDataLen, |
230 | struct iSeries_Device_Node *DevNode) | 186 | HvAgentId agent, u8 *frame, char card[4]) |
231 | { | 187 | { |
232 | u8 *TagPtr = VpdData; | 188 | u8 *TagPtr = VpdData; |
233 | int DataLen = VpdDataLen - 3; | 189 | int DataLen = VpdDataLen - 3; |
190 | u8 PhbId; | ||
234 | 191 | ||
235 | while ((*TagPtr != VpdEndOfAreaTag) && (DataLen > 0)) { | 192 | while ((*TagPtr != VpdEndOfAreaTag) && (DataLen > 0)) { |
236 | int AreaLen = *(TagPtr + 1) + (*(TagPtr + 2) * 256); | 193 | int AreaLen = *(TagPtr + 1) + (*(TagPtr + 2) * 256); |
237 | u8 *AreaData = TagPtr + 3; | 194 | u8 *AreaData = TagPtr + 3; |
238 | 195 | ||
239 | if (*TagPtr == VpdIdStringTag) | 196 | if (*TagPtr == VpdIdStringTag) |
240 | DevNode->PhbId = iSeries_Parse_PhbId(AreaData, AreaLen); | 197 | PhbId = iSeries_Parse_PhbId(AreaData, AreaLen); |
241 | else if (*TagPtr == VpdVendorAreaTag) | 198 | else if (*TagPtr == VpdVendorAreaTag) |
242 | iSeries_Parse_MfgArea(AreaData, AreaLen, DevNode); | 199 | iSeries_Parse_MfgArea(AreaData, AreaLen, |
200 | agent, &PhbId, frame, card); | ||
243 | /* Point to next Area. */ | 201 | /* Point to next Area. */ |
244 | TagPtr = AreaData + AreaLen; | 202 | TagPtr = AreaData + AreaLen; |
245 | DataLen -= AreaLen; | 203 | DataLen -= AreaLen; |
246 | } | 204 | } |
247 | } | 205 | } |
248 | 206 | ||
249 | void iSeries_Get_Location_Code(struct iSeries_Device_Node *DevNode) | 207 | static void __init iSeries_Get_Location_Code(u16 bus, HvAgentId agent, |
208 | u8 *frame, char card[4]) | ||
250 | { | 209 | { |
251 | int BusVpdLen = 0; | 210 | int BusVpdLen = 0; |
252 | u8 *BusVpdPtr = (u8 *)kmalloc(BUS_VPDSIZE, GFP_KERNEL); | 211 | u8 *BusVpdPtr = kmalloc(BUS_VPDSIZE, GFP_KERNEL); |
253 | 212 | ||
254 | if (BusVpdPtr == NULL) { | 213 | if (BusVpdPtr == NULL) { |
255 | printk("PCI: Bus VPD Buffer allocation failure.\n"); | 214 | printk("PCI: Bus VPD Buffer allocation failure.\n"); |
256 | return; | 215 | return; |
257 | } | 216 | } |
258 | BusVpdLen = HvCallPci_getBusVpd(ISERIES_BUS(DevNode), | 217 | BusVpdLen = HvCallPci_getBusVpd(bus, ISERIES_HV_ADDR(BusVpdPtr), |
259 | ISERIES_HV_ADDR(BusVpdPtr), | ||
260 | BUS_VPDSIZE); | 218 | BUS_VPDSIZE); |
261 | if (BusVpdLen == 0) { | 219 | if (BusVpdLen == 0) { |
262 | kfree(BusVpdPtr); | ||
263 | printk("PCI: Bus VPD Buffer zero length.\n"); | 220 | printk("PCI: Bus VPD Buffer zero length.\n"); |
264 | return; | 221 | goto out_free; |
265 | } | 222 | } |
266 | /* printk("PCI: BusVpdPtr: %p, %d\n",BusVpdPtr, BusVpdLen); */ | 223 | /* printk("PCI: BusVpdPtr: %p, %d\n",BusVpdPtr, BusVpdLen); */ |
267 | /* Make sure this is what I think it is */ | 224 | /* Make sure this is what I think it is */ |
268 | if (*BusVpdPtr != VpdIdStringTag) { /* 0x82 */ | 225 | if (*BusVpdPtr != VpdIdStringTag) { /* 0x82 */ |
269 | printk("PCI: Bus VPD Buffer missing starting tag.\n"); | 226 | printk("PCI: Bus VPD Buffer missing starting tag.\n"); |
270 | kfree(BusVpdPtr); | 227 | goto out_free; |
271 | return; | ||
272 | } | 228 | } |
273 | iSeries_Parse_Vpd(BusVpdPtr,BusVpdLen, DevNode); | 229 | iSeries_Parse_Vpd(BusVpdPtr, BusVpdLen, agent, frame, card); |
274 | sprintf(DevNode->Location, "Frame%3d, Card %-4s", DevNode->FrameId, | 230 | out_free: |
275 | DevNode->CardLocation); | ||
276 | kfree(BusVpdPtr); | 231 | kfree(BusVpdPtr); |
277 | } | 232 | } |
233 | |||
234 | /* | ||
235 | * Prints the device information. | ||
236 | * - Pass in pci_dev* pointer to the device. | ||
237 | * - Pass in the device count | ||
238 | * | ||
239 | * Format: | ||
240 | * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet | ||
241 | * controller | ||
242 | */ | ||
243 | void __init iSeries_Device_Information(struct pci_dev *PciDev, int count) | ||
244 | { | ||
245 | struct iSeries_Device_Node *DevNode = PciDev->sysdata; | ||
246 | u16 bus; | ||
247 | u8 frame; | ||
248 | char card[4]; | ||
249 | HvSubBusNumber subbus; | ||
250 | HvAgentId agent; | ||
251 | |||
252 | if (DevNode == NULL) { | ||
253 | printk("%d. PCI: iSeries_Device_Information DevNode is NULL\n", | ||
254 | count); | ||
255 | return; | ||
256 | } | ||
257 | |||
258 | bus = ISERIES_BUS(DevNode); | ||
259 | subbus = ISERIES_SUBBUS(DevNode); | ||
260 | agent = ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus), | ||
261 | ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus)); | ||
262 | iSeries_Get_Location_Code(bus, agent, &frame, card); | ||
263 | |||
264 | printk("%d. PCI: Bus%3d, Device%3d, Vendor %04X Frame%3d, Card %4s ", | ||
265 | count, bus, PCI_SLOT(PciDev->devfn), PciDev->vendor, | ||
266 | frame, card); | ||
267 | if (pci_class_name(PciDev->class >> 8) == 0) | ||
268 | printk("0x%04X\n", (int)(PciDev->class >> 8)); | ||
269 | else | ||
270 | printk("%s\n", pci_class_name(PciDev->class >> 8)); | ||
271 | } | ||