Skip to content

Commit a0d0fd7

Browse files
Vasundhara Volamdavem330
authored andcommitted
bnxt_en: Read partno and serialno of the board from VPD
Store the part number and serial number information from VPD in the bnxt structure. Follow up patch will add the support to display the information via devlink command. Signed-off-by: Vasundhara Volam <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 16efafa commit a0d0fd7

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11752,6 +11752,63 @@ static int bnxt_init_mac_addr(struct bnxt *bp)
1175211752
return rc;
1175311753
}
1175411754

11755+
#define BNXT_VPD_LEN 512
11756+
static void bnxt_vpd_read_info(struct bnxt *bp)
11757+
{
11758+
struct pci_dev *pdev = bp->pdev;
11759+
int i, len, pos, ro_size;
11760+
ssize_t vpd_size;
11761+
u8 *vpd_data;
11762+
11763+
vpd_data = kmalloc(BNXT_VPD_LEN, GFP_KERNEL);
11764+
if (!vpd_data)
11765+
return;
11766+
11767+
vpd_size = pci_read_vpd(pdev, 0, BNXT_VPD_LEN, vpd_data);
11768+
if (vpd_size <= 0) {
11769+
netdev_err(bp->dev, "Unable to read VPD\n");
11770+
goto exit;
11771+
}
11772+
11773+
i = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
11774+
if (i < 0) {
11775+
netdev_err(bp->dev, "VPD READ-Only not found\n");
11776+
goto exit;
11777+
}
11778+
11779+
ro_size = pci_vpd_lrdt_size(&vpd_data[i]);
11780+
i += PCI_VPD_LRDT_TAG_SIZE;
11781+
if (i + ro_size > vpd_size)
11782+
goto exit;
11783+
11784+
pos = pci_vpd_find_info_keyword(vpd_data, i, ro_size,
11785+
PCI_VPD_RO_KEYWORD_PARTNO);
11786+
if (pos < 0)
11787+
goto read_sn;
11788+
11789+
len = pci_vpd_info_field_size(&vpd_data[pos]);
11790+
pos += PCI_VPD_INFO_FLD_HDR_SIZE;
11791+
if (len + pos > vpd_size)
11792+
goto read_sn;
11793+
11794+
strlcpy(bp->board_partno, &vpd_data[pos], min(len, BNXT_VPD_FLD_LEN));
11795+
11796+
read_sn:
11797+
pos = pci_vpd_find_info_keyword(vpd_data, i, ro_size,
11798+
PCI_VPD_RO_KEYWORD_SERIALNO);
11799+
if (pos < 0)
11800+
goto exit;
11801+
11802+
len = pci_vpd_info_field_size(&vpd_data[pos]);
11803+
pos += PCI_VPD_INFO_FLD_HDR_SIZE;
11804+
if (len + pos > vpd_size)
11805+
goto exit;
11806+
11807+
strlcpy(bp->board_serialno, &vpd_data[pos], min(len, BNXT_VPD_FLD_LEN));
11808+
exit:
11809+
kfree(vpd_data);
11810+
}
11811+
1175511812
static int bnxt_pcie_dsn_get(struct bnxt *bp, u8 dsn[])
1175611813
{
1175711814
struct pci_dev *pdev = bp->pdev;
@@ -11809,6 +11866,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1180911866
dev->ethtool_ops = &bnxt_ethtool_ops;
1181011867
pci_set_drvdata(pdev, dev);
1181111868

11869+
bnxt_vpd_read_info(bp);
11870+
1181211871
rc = bnxt_alloc_hwrm_resources(bp);
1181311872
if (rc)
1181411873
goto init_err_pci_clean;

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,10 @@ struct bnxt {
15001500
(chip_num) == CHIP_NUM_58804 || \
15011501
(chip_num) == CHIP_NUM_58808)
15021502

1503+
#define BNXT_VPD_FLD_LEN 32
1504+
char board_partno[BNXT_VPD_FLD_LEN];
1505+
char board_serialno[BNXT_VPD_FLD_LEN];
1506+
15031507
struct net_device *dev;
15041508
struct pci_dev *pdev;
15051509

0 commit comments

Comments
 (0)