mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 19:43:40 +02:00
bnx2x: Read VPD with pci_vpd_alloc()
Use pci_vpd_alloc() to dynamically allocate a properly sized buffer and read the full VPD data into it. This simplifies the code, and we no longer have to make assumptions about VPD size. Link: https://lore.kernel.org/r/821a334d-ff9d-386e-5f42-9b620ab3dbfa@gmail.com Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
parent
35e7f1be79
commit
df87589475
|
|
@ -2407,7 +2407,6 @@ void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id,
|
||||||
#define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
|
#define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BNX2X_VPD_LEN 128
|
|
||||||
#define VENDOR_ID_LEN 4
|
#define VENDOR_ID_LEN 4
|
||||||
|
|
||||||
#define VF_ACQUIRE_THRESH 3
|
#define VF_ACQUIRE_THRESH 3
|
||||||
|
|
|
||||||
|
|
@ -12189,50 +12189,29 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
|
||||||
|
|
||||||
static void bnx2x_read_fwinfo(struct bnx2x *bp)
|
static void bnx2x_read_fwinfo(struct bnx2x *bp)
|
||||||
{
|
{
|
||||||
int cnt, i, block_end, rodi;
|
int i, block_end, rodi;
|
||||||
char vpd_start[BNX2X_VPD_LEN+1];
|
|
||||||
char str_id_reg[VENDOR_ID_LEN+1];
|
char str_id_reg[VENDOR_ID_LEN+1];
|
||||||
char str_id_cap[VENDOR_ID_LEN+1];
|
char str_id_cap[VENDOR_ID_LEN+1];
|
||||||
char *vpd_data;
|
unsigned int vpd_len;
|
||||||
char *vpd_extended_data = NULL;
|
u8 *vpd_data, len;
|
||||||
u8 len;
|
|
||||||
|
|
||||||
cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
|
|
||||||
memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
|
memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
|
||||||
|
|
||||||
if (cnt < BNX2X_VPD_LEN)
|
vpd_data = pci_vpd_alloc(bp->pdev, &vpd_len);
|
||||||
goto out_not_found;
|
if (IS_ERR(vpd_data))
|
||||||
|
return;
|
||||||
|
|
||||||
/* VPD RO tag should be first tag after identifier string, hence
|
/* VPD RO tag should be first tag after identifier string, hence
|
||||||
* we should be able to find it in first BNX2X_VPD_LEN chars
|
* we should be able to find it in first BNX2X_VPD_LEN chars
|
||||||
*/
|
*/
|
||||||
i = pci_vpd_find_tag(vpd_start, BNX2X_VPD_LEN, PCI_VPD_LRDT_RO_DATA);
|
i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
goto out_not_found;
|
goto out_not_found;
|
||||||
|
|
||||||
block_end = i + PCI_VPD_LRDT_TAG_SIZE +
|
block_end = i + PCI_VPD_LRDT_TAG_SIZE +
|
||||||
pci_vpd_lrdt_size(&vpd_start[i]);
|
pci_vpd_lrdt_size(&vpd_data[i]);
|
||||||
|
|
||||||
i += PCI_VPD_LRDT_TAG_SIZE;
|
i += PCI_VPD_LRDT_TAG_SIZE;
|
||||||
|
|
||||||
if (block_end > BNX2X_VPD_LEN) {
|
|
||||||
vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
|
|
||||||
if (vpd_extended_data == NULL)
|
|
||||||
goto out_not_found;
|
|
||||||
|
|
||||||
/* read rest of vpd image into vpd_extended_data */
|
|
||||||
memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
|
|
||||||
cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
|
|
||||||
block_end - BNX2X_VPD_LEN,
|
|
||||||
vpd_extended_data + BNX2X_VPD_LEN);
|
|
||||||
if (cnt < (block_end - BNX2X_VPD_LEN))
|
|
||||||
goto out_not_found;
|
|
||||||
vpd_data = vpd_extended_data;
|
|
||||||
} else
|
|
||||||
vpd_data = vpd_start;
|
|
||||||
|
|
||||||
/* now vpd_data holds full vpd content in both cases */
|
|
||||||
|
|
||||||
rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
|
rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
|
||||||
PCI_VPD_RO_KEYWORD_MFR_ID);
|
PCI_VPD_RO_KEYWORD_MFR_ID);
|
||||||
if (rodi < 0)
|
if (rodi < 0)
|
||||||
|
|
@ -12258,17 +12237,14 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp)
|
||||||
|
|
||||||
rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
|
rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
|
||||||
|
|
||||||
if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
|
if (len < 32 && (len + rodi) <= vpd_len) {
|
||||||
memcpy(bp->fw_ver, &vpd_data[rodi], len);
|
memcpy(bp->fw_ver, &vpd_data[rodi], len);
|
||||||
bp->fw_ver[len] = ' ';
|
bp->fw_ver[len] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kfree(vpd_extended_data);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
out_not_found:
|
out_not_found:
|
||||||
kfree(vpd_extended_data);
|
kfree(vpd_data);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
|
static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user