PCI/VPD: Add pci_vpd_check_csum()
VPD checksum information and checksum calculation are specified by PCIe r5.0, sec 6.28.2.2. Therefore checksum handling can and should be moved into the PCI VPD core. Add pci_vpd_check_csum() to validate the VPD checksum. [bhelgaas: split to separate patch] Link: https://lore.kernel.org/r/1643bd7a-088e-1028-c9b0-9d112cf48d63@gmail.com Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
committed by
Bjorn Helgaas
parent
9e515c9f6c
commit
6107e5cb90
@@ -413,6 +413,29 @@ int pci_vpd_find_ro_info_keyword(const void *buf, unsigned int len,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pci_vpd_find_ro_info_keyword);
|
EXPORT_SYMBOL_GPL(pci_vpd_find_ro_info_keyword);
|
||||||
|
|
||||||
|
int pci_vpd_check_csum(const void *buf, unsigned int len)
|
||||||
|
{
|
||||||
|
const u8 *vpd = buf;
|
||||||
|
unsigned int size;
|
||||||
|
u8 csum = 0;
|
||||||
|
int rv_start;
|
||||||
|
|
||||||
|
rv_start = pci_vpd_find_ro_info_keyword(buf, len, PCI_VPD_RO_KEYWORD_CHKSUM, &size);
|
||||||
|
if (rv_start == -ENOENT) /* no checksum in VPD */
|
||||||
|
return 1;
|
||||||
|
else if (rv_start < 0)
|
||||||
|
return rv_start;
|
||||||
|
|
||||||
|
if (!size)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
while (rv_start >= 0)
|
||||||
|
csum += vpd[rv_start--];
|
||||||
|
|
||||||
|
return csum ? -EILSEQ : 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(pci_vpd_check_csum);
|
||||||
|
|
||||||
#ifdef CONFIG_PCI_QUIRKS
|
#ifdef CONFIG_PCI_QUIRKS
|
||||||
/*
|
/*
|
||||||
* Quirk non-zero PCI functions to route VPD access through function 0 for
|
* Quirk non-zero PCI functions to route VPD access through function 0 for
|
||||||
|
|||||||
@@ -2376,6 +2376,15 @@ int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
|
|||||||
int pci_vpd_find_ro_info_keyword(const void *buf, unsigned int len,
|
int pci_vpd_find_ro_info_keyword(const void *buf, unsigned int len,
|
||||||
const char *kw, unsigned int *size);
|
const char *kw, unsigned int *size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pci_vpd_check_csum - Check VPD checksum
|
||||||
|
* @buf: Pointer to buffered VPD data
|
||||||
|
* @len: VPD size
|
||||||
|
*
|
||||||
|
* Returns 1 if VPD has no checksum, otherwise 0 or an errno
|
||||||
|
*/
|
||||||
|
int pci_vpd_check_csum(const void *buf, unsigned int len);
|
||||||
|
|
||||||
/* PCI <-> OF binding helpers */
|
/* PCI <-> OF binding helpers */
|
||||||
#ifdef CONFIG_OF
|
#ifdef CONFIG_OF
|
||||||
struct device_node;
|
struct device_node;
|
||||||
|
|||||||
Reference in New Issue
Block a user