PCI/VPD: Embed struct pci_vpd in struct pci_dev

Now that struct pci_vpd is really small, simplify the code by embedding
struct pci_vpd directly in struct pci_dev instead of dynamically allocating
it.

Link: https://lore.kernel.org/r/d898489e-22ba-71f1-2f31-f1a78dc15849@gmail.com
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
Heiner Kallweit 2021-08-08 19:21:56 +02:00 committed by Bjorn Helgaas
parent 22ff2bcec7
commit fd00faa375
3 changed files with 21 additions and 52 deletions

View file

@ -2225,7 +2225,6 @@ static void pci_release_capabilities(struct pci_dev *dev)
{ {
pci_aer_exit(dev); pci_aer_exit(dev);
pci_rcec_exit(dev); pci_rcec_exit(dev);
pci_vpd_release(dev);
pci_iov_release(dev); pci_iov_release(dev);
pci_free_cap_save_buffers(dev); pci_free_cap_save_buffers(dev);
} }

View file

@ -13,12 +13,6 @@
/* VPD access through PCI 2.2+ VPD capability */ /* VPD access through PCI 2.2+ VPD capability */
struct pci_vpd {
struct mutex lock;
unsigned int len;
u8 cap;
};
static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev) static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev)
{ {
return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
@ -37,7 +31,7 @@ static size_t pci_vpd_size(struct pci_dev *dev)
unsigned char tag, header[1+2]; /* 1 byte tag, 2 bytes length */ unsigned char tag, header[1+2]; /* 1 byte tag, 2 bytes length */
/* Otherwise the following reads would fail. */ /* Otherwise the following reads would fail. */
dev->vpd->len = PCI_VPD_MAX_SIZE; dev->vpd.len = PCI_VPD_MAX_SIZE;
while (pci_read_vpd(dev, off, 1, header) == 1) { while (pci_read_vpd(dev, off, 1, header) == 1) {
size = 0; size = 0;
@ -89,7 +83,7 @@ static size_t pci_vpd_size(struct pci_dev *dev)
*/ */
static int pci_vpd_wait(struct pci_dev *dev, bool set) static int pci_vpd_wait(struct pci_dev *dev, bool set)
{ {
struct pci_vpd *vpd = dev->vpd; struct pci_vpd *vpd = &dev->vpd;
unsigned long timeout = jiffies + msecs_to_jiffies(125); unsigned long timeout = jiffies + msecs_to_jiffies(125);
unsigned long max_sleep = 16; unsigned long max_sleep = 16;
u16 status; u16 status;
@ -119,12 +113,12 @@ static int pci_vpd_wait(struct pci_dev *dev, bool set)
static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
void *arg) void *arg)
{ {
struct pci_vpd *vpd = dev->vpd; struct pci_vpd *vpd = &dev->vpd;
int ret = 0; int ret = 0;
loff_t end = pos + count; loff_t end = pos + count;
u8 *buf = arg; u8 *buf = arg;
if (!vpd) if (!vpd->cap)
return -ENODEV; return -ENODEV;
if (pos < 0) if (pos < 0)
@ -186,12 +180,12 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
const void *arg) const void *arg)
{ {
struct pci_vpd *vpd = dev->vpd; struct pci_vpd *vpd = &dev->vpd;
const u8 *buf = arg; const u8 *buf = arg;
loff_t end = pos + count; loff_t end = pos + count;
int ret = 0; int ret = 0;
if (!vpd) if (!vpd->cap)
return -ENODEV; return -ENODEV;
if (pos < 0 || (pos & 3) || (count & 3)) if (pos < 0 || (pos & 3) || (count & 3))
@ -238,25 +232,8 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
void pci_vpd_init(struct pci_dev *dev) void pci_vpd_init(struct pci_dev *dev)
{ {
struct pci_vpd *vpd; dev->vpd.cap = pci_find_capability(dev, PCI_CAP_ID_VPD);
u8 cap; mutex_init(&dev->vpd.lock);
cap = pci_find_capability(dev, PCI_CAP_ID_VPD);
if (!cap)
return;
vpd = kzalloc(sizeof(*vpd), GFP_ATOMIC);
if (!vpd)
return;
mutex_init(&vpd->lock);
vpd->cap = cap;
dev->vpd = vpd;
}
void pci_vpd_release(struct pci_dev *dev)
{
kfree(dev->vpd);
} }
static ssize_t vpd_read(struct file *filp, struct kobject *kobj, static ssize_t vpd_read(struct file *filp, struct kobject *kobj,
@ -288,7 +265,7 @@ static umode_t vpd_attr_is_visible(struct kobject *kobj,
{ {
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
if (!pdev->vpd) if (!pdev->vpd.cap)
return 0; return 0;
return a->attr.mode; return a->attr.mode;
@ -400,7 +377,7 @@ static void quirk_f0_vpd_link(struct pci_dev *dev)
if (!f0) if (!f0)
return; return;
if (f0->vpd && dev->class == f0->class && if (f0->vpd.cap && dev->class == f0->class &&
dev->vendor == f0->vendor && dev->device == f0->device) dev->vendor == f0->vendor && dev->device == f0->device)
dev->dev_flags |= PCI_DEV_FLAGS_VPD_REF_F0; dev->dev_flags |= PCI_DEV_FLAGS_VPD_REF_F0;
@ -418,10 +395,8 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
*/ */
static void quirk_blacklist_vpd(struct pci_dev *dev) static void quirk_blacklist_vpd(struct pci_dev *dev)
{ {
if (dev->vpd) { dev->vpd.len = PCI_VPD_SZ_INVALID;
dev->vpd->len = PCI_VPD_SZ_INVALID; pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n");
pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n");
}
} }
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0060, quirk_blacklist_vpd); DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0060, quirk_blacklist_vpd);
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x007c, quirk_blacklist_vpd); DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x007c, quirk_blacklist_vpd);
@ -443,16 +418,6 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, PCI_ANY_ID,
DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031, DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031,
PCI_CLASS_BRIDGE_PCI, 8, quirk_blacklist_vpd); PCI_CLASS_BRIDGE_PCI, 8, quirk_blacklist_vpd);
static void pci_vpd_set_size(struct pci_dev *dev, size_t len)
{
struct pci_vpd *vpd = dev->vpd;
if (!vpd || len == 0 || len > PCI_VPD_MAX_SIZE)
return;
vpd->len = len;
}
static void quirk_chelsio_extend_vpd(struct pci_dev *dev) static void quirk_chelsio_extend_vpd(struct pci_dev *dev)
{ {
int chip = (dev->device & 0xf000) >> 12; int chip = (dev->device & 0xf000) >> 12;
@ -471,9 +436,9 @@ static void quirk_chelsio_extend_vpd(struct pci_dev *dev)
* limits. * limits.
*/ */
if (chip == 0x0 && prod >= 0x20) if (chip == 0x0 && prod >= 0x20)
pci_vpd_set_size(dev, 8192); dev->vpd.len = 8192;
else if (chip >= 0x4 && func < 0x8) else if (chip >= 0x4 && func < 0x8)
pci_vpd_set_size(dev, 2048); dev->vpd.len = 2048;
} }
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID, DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID,

View file

@ -300,9 +300,14 @@ struct pci_cap_saved_state {
struct pci_cap_saved_data cap; struct pci_cap_saved_data cap;
}; };
struct pci_vpd {
struct mutex lock;
unsigned int len;
u8 cap;
};
struct irq_affinity; struct irq_affinity;
struct pcie_link_state; struct pcie_link_state;
struct pci_vpd;
struct pci_sriov; struct pci_sriov;
struct pci_p2pdma; struct pci_p2pdma;
struct rcec_ea; struct rcec_ea;
@ -473,7 +478,7 @@ struct pci_dev {
#ifdef CONFIG_PCI_MSI #ifdef CONFIG_PCI_MSI
const struct attribute_group **msi_irq_groups; const struct attribute_group **msi_irq_groups;
#endif #endif
struct pci_vpd *vpd; struct pci_vpd vpd;
#ifdef CONFIG_PCIE_DPC #ifdef CONFIG_PCIE_DPC
u16 dpc_cap; u16 dpc_cap;
unsigned int dpc_rp_extensions:1; unsigned int dpc_rp_extensions:1;