Change PCI VPD API which was only used by sysfs to something usable
in drivers.
* move iteration over multiple words to the low level
* cleanup types of arguments
* add exportable wrapper
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
--- a/drivers/pci/access.c 2008-09-03 09:01:53.000000000 -0700
+++ b/drivers/pci/access.c 2008-09-03 11:47:41.000000000 -0700
@@ -66,6 +66,39 @@ EXPORT_SYMBOL(pci_bus_write_config_byte)
EXPORT_SYMBOL(pci_bus_write_config_word);
EXPORT_SYMBOL(pci_bus_write_config_dword);
+
+/**
+ * pci_read_vpd - Read one entry from Vital Product Data
+ * @dev: pci device struct
+ * @pos: offset in vpd space
+ * @count: number of bytes to read
+ * @buf: pointer to where to store result
+ *
+ */
+int pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf)
+{
+ if (!dev->vpd || !dev->vpd->ops)
+ return -ENODEV;
+ return dev->vpd->ops->read(dev, pos, count, buf);
+}
+EXPORT_SYMBOL(pci_read_vpd);
+
+/**
+ * pci_write_vpd - Write entry to Vital Product Data
+ * @dev: pci device struct
+ * @pos: offset in vpd space
+ * @count: number of bytes to read
+ * @val: value to write
+ *
+ */
+int pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf)
+{
+ if (!dev->vpd || !dev->vpd->ops)
+ return -ENODEV;
+ return dev->vpd->ops->write(dev, pos, count, buf);
+}
+EXPORT_SYMBOL(pci_write_vpd);
+
/*
* The following routines are to prevent the user from accessing PCI config
* space when it's unsafe to do so. Some devices require this during BIST and
@@ -170,89 +203,93 @@ static int pci_vpd_pci22_wait(struct pci
return ret;
}
-static int pci_vpd_pci22_read(struct pci_dev *dev, int pos, int size,
- char *buf)
+static int pci_vpd_pci22_read(struct pci_dev *dev, loff_t pos, size_t count,
+ void *buf)
{
struct pci_vpd_pci22 *vpd =
container_of(dev->vpd, struct pci_vpd_pci22, base);
- u32 val;
- int ret;
- int begin, end, i;
+ int ret = 0;
+ loff_t end = pos + ...Change sky2 driver (in netdev next tree) to use vpd access routines.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Note: other usage of vpd internal access routines will go away in later patches.
---
Patch against netdev-2.6#upstream-next assumes the previous PCI API change.
--- a/drivers/net/sky2.c 2008-09-03 11:35:47.000000000 -0700
+++ b/drivers/net/sky2.c 2008-09-03 11:44:06.000000000 -0700
@@ -4199,10 +4199,9 @@ static int __devinit pci_wake_enabled(st
static void __devinit sky2_vpd_info(struct sky2_hw *hw)
{
- int cap = pci_find_capability(hw->pdev, PCI_CAP_ID_VPD);
- const u8 *p;
- u8 *vpd_buf = NULL;
- u16 len;
+ loff_t offs;
+ u8 len;
+ u8 tag[3];
static struct vpd_tag {
char tag[2];
char *label;
@@ -4211,47 +4210,48 @@ static void __devinit sky2_vpd_info(stru
{ "EC", "Engineering Level" },
{ "MN", "Manufacturer" },
};
+ char str[128];
- if (!cap)
- goto out;
-
- vpd_buf = kmalloc(VPD_SIZE, GFP_KERNEL);
- if (!vpd_buf)
- goto out;
+ if (pci_read_vpd(hw->pdev, 0, sizeof(tag), tag) < 0)
+ return;
+ if (tag[0] != VPD_MAGIC)
+ return;
+ len = tag[1];
+ if (len == 0 || len > sizeof(str))
+ return;
- if (sky2_vpd_read(hw, cap, vpd_buf, 0, VPD_SIZE))
- goto out;
+ offs = 3;
+ if (pci_read_vpd(hw->pdev, offs, len, str) < 0)
+ return;
- if (vpd_buf[0] != VPD_MAGIC)
- goto out;
- len = vpd_buf[1];
- if (len == 0 || len > VPD_SIZE - 4)
- goto out;
- p = vpd_buf + 3;
- dev_info(&hw->pdev->dev, "%.*s\n", len, p);
- p += len;
+ dev_info(&hw->pdev->dev, "%.*s\n", len, str);
- while (p < vpd_buf + VPD_SIZE - 4) {
+ for(;;) {
int i;
- if (!memcmp("RW", p, 2)) /* end marker */
+ offs += len;
+ if (pci_read_vpd(hw->pdev, offs, sizeof(tag), tag) < 0)
break;
- len = p[2];
- if (len > (p - vpd_buf) - 4)
+ if (!memcmp("RW", tag, 2)) /* end marker */
+ break;
+
+ offs += sizeof(tag);
+ len = tag[2];
+ if (len > sizeof(str))
break;
for (i = 0; i < ...Acked-by: me I presume this will go via PCI tree? --
The sky2 bits too? Sure, that's fine with me. I'll stuff it into my linux-next tree tomorrow after a quick look. Thanks, Jesse --
