vpd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PCI VPD support
  4. *
  5. * Copyright (C) 2010 Broadcom Corporation.
  6. */
  7. #include <linux/pci.h>
  8. #include <linux/delay.h>
  9. #include <linux/export.h>
  10. #include <linux/sched/signal.h>
  11. #include "pci.h"
  12. /* VPD access through PCI 2.2+ VPD capability */
  13. struct pci_vpd_ops {
  14. ssize_t (*read)(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
  15. ssize_t (*write)(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
  16. int (*set_size)(struct pci_dev *dev, size_t len);
  17. };
  18. struct pci_vpd {
  19. const struct pci_vpd_ops *ops;
  20. struct bin_attribute *attr; /* Descriptor for sysfs VPD entry */
  21. struct mutex lock;
  22. unsigned int len;
  23. u16 flag;
  24. u8 cap;
  25. unsigned int busy:1;
  26. unsigned int valid:1;
  27. };
  28. /**
  29. * pci_read_vpd - Read one entry from Vital Product Data
  30. * @dev: pci device struct
  31. * @pos: offset in vpd space
  32. * @count: number of bytes to read
  33. * @buf: pointer to where to store result
  34. */
  35. ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf)
  36. {
  37. if (!dev->vpd || !dev->vpd->ops)
  38. return -ENODEV;
  39. return dev->vpd->ops->read(dev, pos, count, buf);
  40. }
  41. EXPORT_SYMBOL(pci_read_vpd);
  42. /**
  43. * pci_write_vpd - Write entry to Vital Product Data
  44. * @dev: pci device struct
  45. * @pos: offset in vpd space
  46. * @count: number of bytes to write
  47. * @buf: buffer containing write data
  48. */
  49. ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf)
  50. {
  51. if (!dev->vpd || !dev->vpd->ops)
  52. return -ENODEV;
  53. return dev->vpd->ops->write(dev, pos, count, buf);
  54. }
  55. EXPORT_SYMBOL(pci_write_vpd);
  56. /**
  57. * pci_set_vpd_size - Set size of Vital Product Data space
  58. * @dev: pci device struct
  59. * @len: size of vpd space
  60. */
  61. int pci_set_vpd_size(struct pci_dev *dev, size_t len)
  62. {
  63. if (!dev->vpd || !dev->vpd->ops)
  64. return -ENODEV;
  65. return dev->vpd->ops->set_size(dev, len);
  66. }
  67. EXPORT_SYMBOL(pci_set_vpd_size);
  68. #define PCI_VPD_MAX_SIZE (PCI_VPD_ADDR_MASK + 1)
  69. /**
  70. * pci_vpd_size - determine actual size of Vital Product Data
  71. * @dev: pci device struct
  72. * @old_size: current assumed size, also maximum allowed size
  73. */
  74. static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size)
  75. {
  76. size_t off = 0;
  77. unsigned char header[1+2]; /* 1 byte tag, 2 bytes length */
  78. while (off < old_size &&
  79. pci_read_vpd(dev, off, 1, header) == 1) {
  80. unsigned char tag;
  81. if (header[0] & PCI_VPD_LRDT) {
  82. /* Large Resource Data Type Tag */
  83. tag = pci_vpd_lrdt_tag(header);
  84. /* Only read length from known tag items */
  85. if ((tag == PCI_VPD_LTIN_ID_STRING) ||
  86. (tag == PCI_VPD_LTIN_RO_DATA) ||
  87. (tag == PCI_VPD_LTIN_RW_DATA)) {
  88. if (pci_read_vpd(dev, off+1, 2,
  89. &header[1]) != 2) {
  90. pci_warn(dev, "invalid large VPD tag %02x size at offset %zu",
  91. tag, off + 1);
  92. return 0;
  93. }
  94. off += PCI_VPD_LRDT_TAG_SIZE +
  95. pci_vpd_lrdt_size(header);
  96. }
  97. } else {
  98. /* Short Resource Data Type Tag */
  99. off += PCI_VPD_SRDT_TAG_SIZE +
  100. pci_vpd_srdt_size(header);
  101. tag = pci_vpd_srdt_tag(header);
  102. }
  103. if (tag == PCI_VPD_STIN_END) /* End tag descriptor */
  104. return off;
  105. if ((tag != PCI_VPD_LTIN_ID_STRING) &&
  106. (tag != PCI_VPD_LTIN_RO_DATA) &&
  107. (tag != PCI_VPD_LTIN_RW_DATA)) {
  108. pci_warn(dev, "invalid %s VPD tag %02x at offset %zu",
  109. (header[0] & PCI_VPD_LRDT) ? "large" : "short",
  110. tag, off);
  111. return 0;
  112. }
  113. }
  114. return 0;
  115. }
  116. /*
  117. * Wait for last operation to complete.
  118. * This code has to spin since there is no other notification from the PCI
  119. * hardware. Since the VPD is often implemented by serial attachment to an
  120. * EEPROM, it may take many milliseconds to complete.
  121. *
  122. * Returns 0 on success, negative values indicate error.
  123. */
  124. static int pci_vpd_wait(struct pci_dev *dev)
  125. {
  126. struct pci_vpd *vpd = dev->vpd;
  127. unsigned long timeout = jiffies + msecs_to_jiffies(125);
  128. unsigned long max_sleep = 16;
  129. u16 status;
  130. int ret;
  131. if (!vpd->busy)
  132. return 0;
  133. while (time_before(jiffies, timeout)) {
  134. ret = pci_user_read_config_word(dev, vpd->cap + PCI_VPD_ADDR,
  135. &status);
  136. if (ret < 0)
  137. return ret;
  138. if ((status & PCI_VPD_ADDR_F) == vpd->flag) {
  139. vpd->busy = 0;
  140. return 0;
  141. }
  142. if (fatal_signal_pending(current))
  143. return -EINTR;
  144. usleep_range(10, max_sleep);
  145. if (max_sleep < 1024)
  146. max_sleep *= 2;
  147. }
  148. pci_warn(dev, "VPD access failed. This is likely a firmware bug on this device. Contact the card vendor for a firmware update\n");
  149. return -ETIMEDOUT;
  150. }
  151. static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
  152. void *arg)
  153. {
  154. struct pci_vpd *vpd = dev->vpd;
  155. int ret;
  156. loff_t end = pos + count;
  157. u8 *buf = arg;
  158. if (pos < 0)
  159. return -EINVAL;
  160. if (!vpd->valid) {
  161. vpd->valid = 1;
  162. vpd->len = pci_vpd_size(dev, vpd->len);
  163. }
  164. if (vpd->len == 0)
  165. return -EIO;
  166. if (pos > vpd->len)
  167. return 0;
  168. if (end > vpd->len) {
  169. end = vpd->len;
  170. count = end - pos;
  171. }
  172. if (mutex_lock_killable(&vpd->lock))
  173. return -EINTR;
  174. ret = pci_vpd_wait(dev);
  175. if (ret < 0)
  176. goto out;
  177. while (pos < end) {
  178. u32 val;
  179. unsigned int i, skip;
  180. ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR,
  181. pos & ~3);
  182. if (ret < 0)
  183. break;
  184. vpd->busy = 1;
  185. vpd->flag = PCI_VPD_ADDR_F;
  186. ret = pci_vpd_wait(dev);
  187. if (ret < 0)
  188. break;
  189. ret = pci_user_read_config_dword(dev, vpd->cap + PCI_VPD_DATA, &val);
  190. if (ret < 0)
  191. break;
  192. skip = pos & 3;
  193. for (i = 0; i < sizeof(u32); i++) {
  194. if (i >= skip) {
  195. *buf++ = val;
  196. if (++pos == end)
  197. break;
  198. }
  199. val >>= 8;
  200. }
  201. }
  202. out:
  203. mutex_unlock(&vpd->lock);
  204. return ret ? ret : count;
  205. }
  206. static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
  207. const void *arg)
  208. {
  209. struct pci_vpd *vpd = dev->vpd;
  210. const u8 *buf = arg;
  211. loff_t end = pos + count;
  212. int ret = 0;
  213. if (pos < 0 || (pos & 3) || (count & 3))
  214. return -EINVAL;
  215. if (!vpd->valid) {
  216. vpd->valid = 1;
  217. vpd->len = pci_vpd_size(dev, vpd->len);
  218. }
  219. if (vpd->len == 0)
  220. return -EIO;
  221. if (end > vpd->len)
  222. return -EINVAL;
  223. if (mutex_lock_killable(&vpd->lock))
  224. return -EINTR;
  225. ret = pci_vpd_wait(dev);
  226. if (ret < 0)
  227. goto out;
  228. while (pos < end) {
  229. u32 val;
  230. val = *buf++;
  231. val |= *buf++ << 8;
  232. val |= *buf++ << 16;
  233. val |= *buf++ << 24;
  234. ret = pci_user_write_config_dword(dev, vpd->cap + PCI_VPD_DATA, val);
  235. if (ret < 0)
  236. break;
  237. ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR,
  238. pos | PCI_VPD_ADDR_F);
  239. if (ret < 0)
  240. break;
  241. vpd->busy = 1;
  242. vpd->flag = 0;
  243. ret = pci_vpd_wait(dev);
  244. if (ret < 0)
  245. break;
  246. pos += sizeof(u32);
  247. }
  248. out:
  249. mutex_unlock(&vpd->lock);
  250. return ret ? ret : count;
  251. }
  252. static int pci_vpd_set_size(struct pci_dev *dev, size_t len)
  253. {
  254. struct pci_vpd *vpd = dev->vpd;
  255. if (len == 0 || len > PCI_VPD_MAX_SIZE)
  256. return -EIO;
  257. vpd->valid = 1;
  258. vpd->len = len;
  259. return 0;
  260. }
  261. static const struct pci_vpd_ops pci_vpd_ops = {
  262. .read = pci_vpd_read,
  263. .write = pci_vpd_write,
  264. .set_size = pci_vpd_set_size,
  265. };
  266. static ssize_t pci_vpd_f0_read(struct pci_dev *dev, loff_t pos, size_t count,
  267. void *arg)
  268. {
  269. struct pci_dev *tdev = pci_get_slot(dev->bus,
  270. PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
  271. ssize_t ret;
  272. if (!tdev)
  273. return -ENODEV;
  274. ret = pci_read_vpd(tdev, pos, count, arg);
  275. pci_dev_put(tdev);
  276. return ret;
  277. }
  278. static ssize_t pci_vpd_f0_write(struct pci_dev *dev, loff_t pos, size_t count,
  279. const void *arg)
  280. {
  281. struct pci_dev *tdev = pci_get_slot(dev->bus,
  282. PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
  283. ssize_t ret;
  284. if (!tdev)
  285. return -ENODEV;
  286. ret = pci_write_vpd(tdev, pos, count, arg);
  287. pci_dev_put(tdev);
  288. return ret;
  289. }
  290. static int pci_vpd_f0_set_size(struct pci_dev *dev, size_t len)
  291. {
  292. struct pci_dev *tdev = pci_get_slot(dev->bus,
  293. PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
  294. int ret;
  295. if (!tdev)
  296. return -ENODEV;
  297. ret = pci_set_vpd_size(tdev, len);
  298. pci_dev_put(tdev);
  299. return ret;
  300. }
  301. static const struct pci_vpd_ops pci_vpd_f0_ops = {
  302. .read = pci_vpd_f0_read,
  303. .write = pci_vpd_f0_write,
  304. .set_size = pci_vpd_f0_set_size,
  305. };
  306. int pci_vpd_init(struct pci_dev *dev)
  307. {
  308. struct pci_vpd *vpd;
  309. u8 cap;
  310. cap = pci_find_capability(dev, PCI_CAP_ID_VPD);
  311. if (!cap)
  312. return -ENODEV;
  313. vpd = kzalloc(sizeof(*vpd), GFP_ATOMIC);
  314. if (!vpd)
  315. return -ENOMEM;
  316. vpd->len = PCI_VPD_MAX_SIZE;
  317. if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0)
  318. vpd->ops = &pci_vpd_f0_ops;
  319. else
  320. vpd->ops = &pci_vpd_ops;
  321. mutex_init(&vpd->lock);
  322. vpd->cap = cap;
  323. vpd->busy = 0;
  324. vpd->valid = 0;
  325. dev->vpd = vpd;
  326. return 0;
  327. }
  328. void pci_vpd_release(struct pci_dev *dev)
  329. {
  330. kfree(dev->vpd);
  331. }
  332. static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj,
  333. struct bin_attribute *bin_attr, char *buf,
  334. loff_t off, size_t count)
  335. {
  336. struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
  337. if (bin_attr->size > 0) {
  338. if (off > bin_attr->size)
  339. count = 0;
  340. else if (count > bin_attr->size - off)
  341. count = bin_attr->size - off;
  342. }
  343. return pci_read_vpd(dev, off, count, buf);
  344. }
  345. static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj,
  346. struct bin_attribute *bin_attr, char *buf,
  347. loff_t off, size_t count)
  348. {
  349. struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
  350. if (bin_attr->size > 0) {
  351. if (off > bin_attr->size)
  352. count = 0;
  353. else if (count > bin_attr->size - off)
  354. count = bin_attr->size - off;
  355. }
  356. return pci_write_vpd(dev, off, count, buf);
  357. }
  358. void pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev)
  359. {
  360. int retval;
  361. struct bin_attribute *attr;
  362. if (!dev->vpd)
  363. return;
  364. attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
  365. if (!attr)
  366. return;
  367. sysfs_bin_attr_init(attr);
  368. attr->size = 0;
  369. attr->attr.name = "vpd";
  370. attr->attr.mode = S_IRUSR | S_IWUSR;
  371. attr->read = read_vpd_attr;
  372. attr->write = write_vpd_attr;
  373. retval = sysfs_create_bin_file(&dev->dev.kobj, attr);
  374. if (retval) {
  375. kfree(attr);
  376. return;
  377. }
  378. dev->vpd->attr = attr;
  379. }
  380. void pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev)
  381. {
  382. if (dev->vpd && dev->vpd->attr) {
  383. sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr);
  384. kfree(dev->vpd->attr);
  385. }
  386. }
  387. int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
  388. {
  389. int i;
  390. for (i = off; i < len; ) {
  391. u8 val = buf[i];
  392. if (val & PCI_VPD_LRDT) {
  393. /* Don't return success of the tag isn't complete */
  394. if (i + PCI_VPD_LRDT_TAG_SIZE > len)
  395. break;
  396. if (val == rdt)
  397. return i;
  398. i += PCI_VPD_LRDT_TAG_SIZE +
  399. pci_vpd_lrdt_size(&buf[i]);
  400. } else {
  401. u8 tag = val & ~PCI_VPD_SRDT_LEN_MASK;
  402. if (tag == rdt)
  403. return i;
  404. if (tag == PCI_VPD_SRDT_END)
  405. break;
  406. i += PCI_VPD_SRDT_TAG_SIZE +
  407. pci_vpd_srdt_size(&buf[i]);
  408. }
  409. }
  410. return -ENOENT;
  411. }
  412. EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
  413. int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
  414. unsigned int len, const char *kw)
  415. {
  416. int i;
  417. for (i = off; i + PCI_VPD_INFO_FLD_HDR_SIZE <= off + len;) {
  418. if (buf[i + 0] == kw[0] &&
  419. buf[i + 1] == kw[1])
  420. return i;
  421. i += PCI_VPD_INFO_FLD_HDR_SIZE +
  422. pci_vpd_info_field_size(&buf[i]);
  423. }
  424. return -ENOENT;
  425. }
  426. EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);
  427. #ifdef CONFIG_PCI_QUIRKS
  428. /*
  429. * Quirk non-zero PCI functions to route VPD access through function 0 for
  430. * devices that share VPD resources between functions. The functions are
  431. * expected to be identical devices.
  432. */
  433. static void quirk_f0_vpd_link(struct pci_dev *dev)
  434. {
  435. struct pci_dev *f0;
  436. if (!PCI_FUNC(dev->devfn))
  437. return;
  438. f0 = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
  439. if (!f0)
  440. return;
  441. if (f0->vpd && dev->class == f0->class &&
  442. dev->vendor == f0->vendor && dev->device == f0->device)
  443. dev->dev_flags |= PCI_DEV_FLAGS_VPD_REF_F0;
  444. pci_dev_put(f0);
  445. }
  446. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
  447. PCI_CLASS_NETWORK_ETHERNET, 8, quirk_f0_vpd_link);
  448. /*
  449. * If a device follows the VPD format spec, the PCI core will not read or
  450. * write past the VPD End Tag. But some vendors do not follow the VPD
  451. * format spec, so we can't tell how much data is safe to access. Devices
  452. * may behave unpredictably if we access too much. Blacklist these devices
  453. * so we don't touch VPD at all.
  454. */
  455. static void quirk_blacklist_vpd(struct pci_dev *dev)
  456. {
  457. if (dev->vpd) {
  458. dev->vpd->len = 0;
  459. pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n");
  460. }
  461. }
  462. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0060, quirk_blacklist_vpd);
  463. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x007c, quirk_blacklist_vpd);
  464. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0413, quirk_blacklist_vpd);
  465. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0078, quirk_blacklist_vpd);
  466. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0079, quirk_blacklist_vpd);
  467. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0073, quirk_blacklist_vpd);
  468. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0071, quirk_blacklist_vpd);
  469. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005b, quirk_blacklist_vpd);
  470. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x002f, quirk_blacklist_vpd);
  471. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005d, quirk_blacklist_vpd);
  472. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005f, quirk_blacklist_vpd);
  473. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, PCI_ANY_ID,
  474. quirk_blacklist_vpd);
  475. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_QLOGIC, 0x2261, quirk_blacklist_vpd);
  476. /*
  477. * For Broadcom 5706, 5708, 5709 rev. A nics, any read beyond the
  478. * VPD end tag will hang the device. This problem was initially
  479. * observed when a vpd entry was created in sysfs
  480. * ('/sys/bus/pci/devices/<id>/vpd'). A read to this sysfs entry
  481. * will dump 32k of data. Reading a full 32k will cause an access
  482. * beyond the VPD end tag causing the device to hang. Once the device
  483. * is hung, the bnx2 driver will not be able to reset the device.
  484. * We believe that it is legal to read beyond the end tag and
  485. * therefore the solution is to limit the read/write length.
  486. */
  487. static void quirk_brcm_570x_limit_vpd(struct pci_dev *dev)
  488. {
  489. /*
  490. * Only disable the VPD capability for 5706, 5706S, 5708,
  491. * 5708S and 5709 rev. A
  492. */
  493. if ((dev->device == PCI_DEVICE_ID_NX2_5706) ||
  494. (dev->device == PCI_DEVICE_ID_NX2_5706S) ||
  495. (dev->device == PCI_DEVICE_ID_NX2_5708) ||
  496. (dev->device == PCI_DEVICE_ID_NX2_5708S) ||
  497. ((dev->device == PCI_DEVICE_ID_NX2_5709) &&
  498. (dev->revision & 0xf0) == 0x0)) {
  499. if (dev->vpd)
  500. dev->vpd->len = 0x80;
  501. }
  502. }
  503. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  504. PCI_DEVICE_ID_NX2_5706,
  505. quirk_brcm_570x_limit_vpd);
  506. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  507. PCI_DEVICE_ID_NX2_5706S,
  508. quirk_brcm_570x_limit_vpd);
  509. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  510. PCI_DEVICE_ID_NX2_5708,
  511. quirk_brcm_570x_limit_vpd);
  512. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  513. PCI_DEVICE_ID_NX2_5708S,
  514. quirk_brcm_570x_limit_vpd);
  515. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  516. PCI_DEVICE_ID_NX2_5709,
  517. quirk_brcm_570x_limit_vpd);
  518. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  519. PCI_DEVICE_ID_NX2_5709S,
  520. quirk_brcm_570x_limit_vpd);
  521. static void quirk_chelsio_extend_vpd(struct pci_dev *dev)
  522. {
  523. int chip = (dev->device & 0xf000) >> 12;
  524. int func = (dev->device & 0x0f00) >> 8;
  525. int prod = (dev->device & 0x00ff) >> 0;
  526. /*
  527. * If this is a T3-based adapter, there's a 1KB VPD area at offset
  528. * 0xc00 which contains the preferred VPD values. If this is a T4 or
  529. * later based adapter, the special VPD is at offset 0x400 for the
  530. * Physical Functions (the SR-IOV Virtual Functions have no VPD
  531. * Capabilities). The PCI VPD Access core routines will normally
  532. * compute the size of the VPD by parsing the VPD Data Structure at
  533. * offset 0x000. This will result in silent failures when attempting
  534. * to accesses these other VPD areas which are beyond those computed
  535. * limits.
  536. */
  537. if (chip == 0x0 && prod >= 0x20)
  538. pci_set_vpd_size(dev, 8192);
  539. else if (chip >= 0x4 && func < 0x8)
  540. pci_set_vpd_size(dev, 2048);
  541. }
  542. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID,
  543. quirk_chelsio_extend_vpd);
  544. #endif