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.
17 * The list of all known VPD items and their formats.
18 * Technically, this belongs to the pci.ids file, but the VPD does not seem
19 * to be developed any longer, so we have chosen the easier way.
29 static const struct vpd_item {
34 { 'C','P', F_BINARY, "Extended capability" },
35 { 'E','C', F_TEXT, "Engineering changes" },
36 { 'M','N', F_TEXT, "Manufacture ID" },
37 { 'P','N', F_TEXT, "Part number" },
38 { 'R','V', F_RESVD, "Reserved" },
39 { 'R','W', F_RDWR, "Read-write area" },
40 { 'S','N', F_TEXT, "Serial number" },
41 { 'Y','A', F_TEXT, "Asset tag" },
42 { 'V', 0 , F_TEXT, "Vendor specific" },
43 { 'Y', 0 , F_TEXT, "System specific" },
44 /* Non-standard extensions */
45 { 'C','C', F_TEXT, "CCIN" },
46 { 'F','C', F_TEXT, "Feature code" },
47 { 'F','N', F_TEXT, "FRU" },
48 { 'N','A', F_TEXT, "Network address" },
49 { 'R','M', F_TEXT, "Firmware version" },
50 { 'Z', 0 , F_TEXT, "Product specific" },
51 { 0, 0 , F_BINARY, "Unknown" }
55 print_vpd_string(const byte *buf, word len)
63 ; /* Cards with null-terminated strings have been observed */
64 else if (ch < 32 || ch == 127)
65 printf("\\x%02x", ch);
72 print_vpd_binary(const byte *buf, word len)
75 for (i = 0; i < len; i++)
79 printf("%02x", buf[i]);
84 read_vpd(struct device *d, int pos, byte *buf, int len, byte *csum)
86 if (!pci_read_vpd(d->dev, pos, buf, len))
94 cap_vpd(struct device *d)
96 word res_addr = 0, res_len, part_pos, part_len;
101 printf("Vital Product Data\n");
105 while (res_addr <= PCI_VPD_ADDR_MASK)
107 if (!read_vpd(d, res_addr, &tag, 1, &csum))
111 if (res_addr > PCI_VPD_ADDR_MASK + 1 - 3)
113 if (!read_vpd(d, res_addr + 1, buf, 2, &csum))
115 res_len = buf[0] + (buf[1] << 8);
124 if (res_len > PCI_VPD_ADDR_MASK + 1 - res_addr)
136 printf("\t\tProduct Name: ");
137 while (part_pos < res_len)
139 part_len = res_len - part_pos;
140 if (part_len > sizeof(buf))
141 part_len = sizeof(buf);
142 if (!read_vpd(d, res_addr + part_pos, buf, part_len, &csum))
144 print_vpd_string(buf, part_len);
145 part_pos += part_len;
152 printf("\t\t%s fields:\n",
153 (tag == 0x90) ? "Read-only" : "Read/write");
155 while (part_pos + 3 <= res_len)
158 const struct vpd_item *item;
161 if (!read_vpd(d, res_addr + part_pos, buf, 3, &csum))
167 if (part_len > res_len - part_pos)
170 /* Is this item known? */
171 for (item=vpd_items; item->id1 && item->id1 != id1 ||
172 item->id2 && item->id2 != id2; item++)
175 /* Only read the first byte of the RV field because the
176 * remaining bytes are not included in the checksum. */
177 read_len = (item->format == F_RESVD) ? 1 : part_len;
178 if (!read_vpd(d, res_addr + part_pos, buf, read_len, &csum))
181 printf("\t\t\t[%c%c] %s: ", id1, id2, item->name);
183 switch (item->format)
186 print_vpd_string(buf, part_len);
190 print_vpd_binary(buf, part_len);
194 printf("checksum %s, %d byte(s) reserved\n", csum ? "bad" : "good", part_len - 1);
197 printf("%d byte(s) free\n", part_len);
201 part_pos += part_len;
206 printf("\t\tUnknown %s resource type %02x, will not decode more.\n",
207 (tag & 0x80) ? "large" : "small", tag & ~0x80);
215 printf("\t\tNot readable\n");
217 printf("\t\tNo end tag found\n");