2 * The PCI Utilities -- Show Vital Product Data
4 * Copyright (c) 2008 Solarflare Communications
6 * Written by Ben Hutchings <bhutchings@solarflare.com>
7 * Improved by Martin Mares <mj@ucw.cz>
9 * Can be freely distributed and used under the terms of the GNU GPL.
18 * The list of all known VPD items and their formats.
19 * Technically, this belongs to the pci.ids file, but the VPD does not seem
20 * to be developed any longer, so we have chosen the easier way.
30 static const struct vpd_item {
35 { 'C','P', F_BINARY, "Extended capability" },
36 { 'E','C', F_TEXT, "Engineering changes" },
37 { 'M','N', F_TEXT, "Manufacture ID" },
38 { 'P','N', F_TEXT, "Part number" },
39 { 'R','V', F_RESVD, "Reserved" },
40 { 'R','W', F_RDWR, "Read-write area" },
41 { 'S','N', F_TEXT, "Serial number" },
42 { 'Y','A', F_TEXT, "Asset tag" },
43 { 'V', 0 , F_TEXT, "Vendor specific" },
44 { 'Y', 0 , F_TEXT, "System specific" },
45 /* Non-standard extensions */
46 { 'C','C', F_TEXT, "CCIN" },
47 { 'F','C', F_TEXT, "Feature code" },
48 { 'F','N', F_TEXT, "FRU" },
49 { 'N','A', F_TEXT, "Network address" },
50 { 'R','M', F_TEXT, "Firmware version" },
51 { 'Z', 0 , F_TEXT, "Product specific" },
52 { 0, 0 , F_BINARY, "Unknown" }
56 print_vpd_string(const byte *buf, word len)
64 ; /* Cards with null-terminated strings have been observed */
65 else if (ch < 32 || ch == 127)
66 printf("\\x%02x", ch);
73 print_vpd_binary(const byte *buf, word len)
76 for (i = 0; i < len; i++)
80 printf("%02x", buf[i]);
85 read_vpd(struct device *d, int pos, byte *buf, int len, byte *csum)
87 if (!pci_read_vpd(d->dev, pos, buf, len))
95 cap_vpd(struct device *d)
97 word res_addr = 0, res_len, part_pos, part_len;
102 printf("Vital Product Data\n");
106 while (res_addr <= PCI_VPD_ADDR_MASK)
108 if (!read_vpd(d, res_addr, &tag, 1, &csum))
112 if (res_addr > PCI_VPD_ADDR_MASK + 1 - 3)
114 if (!read_vpd(d, res_addr + 1, buf, 2, &csum))
116 res_len = buf[0] + (buf[1] << 8);
125 if (res_len > PCI_VPD_ADDR_MASK + 1 - res_addr)
137 printf("\t\tProduct Name: ");
138 while (part_pos < res_len)
140 part_len = res_len - part_pos;
141 if (part_len > sizeof(buf))
142 part_len = sizeof(buf);
143 if (!read_vpd(d, res_addr + part_pos, buf, part_len, &csum))
145 print_vpd_string(buf, part_len);
146 part_pos += part_len;
153 printf("\t\t%s fields:\n",
154 (tag == 0x90) ? "Read-only" : "Read/write");
156 while (part_pos + 3 <= res_len)
159 const struct vpd_item *item;
160 byte id[2], id1, id2;
162 if (!read_vpd(d, res_addr + part_pos, buf, 3, &csum))
169 if (part_len > res_len - part_pos)
172 /* Is this item known? */
173 for (item=vpd_items; item->id1 && item->id1 != id1 ||
174 item->id2 && item->id2 != id2; item++)
177 /* Only read the first byte of the RV field because the
178 * remaining bytes are not included in the checksum. */
179 read_len = (item->format == F_RESVD) ? 1 : part_len;
180 if (!read_vpd(d, res_addr + part_pos, buf, read_len, &csum))
184 print_vpd_string(id, 2);
185 printf("] %s: ", item->name);
187 switch (item->format)
190 print_vpd_string(buf, part_len);
194 print_vpd_binary(buf, part_len);
198 printf("checksum %s, %d byte(s) reserved\n", csum ? "bad" : "good", part_len - 1);
201 printf("%d byte(s) free\n", part_len);
205 part_pos += part_len;
210 printf("\t\tUnknown %s resource type %02x, will not decode more.\n",
211 (tag & 0x80) ? "large" : "small", tag & ~0x80);
219 printf("\t\tNot readable\n");
221 printf("\t\tNo end tag found\n");