Skip to content

Commit 0c45d7f

Browse files
Rick Farringtondavem330
authored andcommitted
liquidio: fix use of pf in pass-through mode in a virtual machine
Fix problem when PF is used in pass-through mode in a VM (w/embedded f/w). If host error reading PF num from CN23XX_PCIE_SRIOV_FDL reg, try to retrieve PF num from SLI_PKT(0)_INPUT_CONTROL (initialized by f/w). Signed-off-by: Rick Farrington <ricardo.farrington@cavium.com> Signed-off-by: Felix Manlunas <felix.manlunas@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6eb15e2 commit 0c45d7f

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,14 +1150,50 @@ static void cn23xx_get_pcie_qlmport(struct octeon_device *oct)
11501150
oct->pcie_port);
11511151
}
11521152

1153-
static void cn23xx_get_pf_num(struct octeon_device *oct)
1153+
static int cn23xx_get_pf_num(struct octeon_device *oct)
11541154
{
11551155
u32 fdl_bit = 0;
1156+
u64 pkt0_in_ctl, d64;
1157+
int pfnum, mac, trs, ret;
1158+
1159+
ret = 0;
11561160

11571161
/** Read Function Dependency Link reg to get the function number */
1158-
pci_read_config_dword(oct->pci_dev, CN23XX_PCIE_SRIOV_FDL, &fdl_bit);
1159-
oct->pf_num = ((fdl_bit >> CN23XX_PCIE_SRIOV_FDL_BIT_POS) &
1160-
CN23XX_PCIE_SRIOV_FDL_MASK);
1162+
if (pci_read_config_dword(oct->pci_dev, CN23XX_PCIE_SRIOV_FDL,
1163+
&fdl_bit) == 0) {
1164+
oct->pf_num = ((fdl_bit >> CN23XX_PCIE_SRIOV_FDL_BIT_POS) &
1165+
CN23XX_PCIE_SRIOV_FDL_MASK);
1166+
} else {
1167+
ret = EINVAL;
1168+
1169+
/* Under some virtual environments, extended PCI regs are
1170+
* inaccessible, in which case the above read will have failed.
1171+
* In this case, read the PF number from the
1172+
* SLI_PKT0_INPUT_CONTROL reg (written by f/w)
1173+
*/
1174+
pkt0_in_ctl = octeon_read_csr64(oct,
1175+
CN23XX_SLI_IQ_PKT_CONTROL64(0));
1176+
pfnum = (pkt0_in_ctl >> CN23XX_PKT_INPUT_CTL_PF_NUM_POS) &
1177+
CN23XX_PKT_INPUT_CTL_PF_NUM_MASK;
1178+
mac = (octeon_read_csr(oct, CN23XX_SLI_MAC_NUMBER)) & 0xff;
1179+
1180+
/* validate PF num by reading RINFO; f/w writes RINFO.trs == 1*/
1181+
d64 = octeon_read_csr64(oct,
1182+
CN23XX_SLI_PKT_MAC_RINFO64(mac, pfnum));
1183+
trs = (int)(d64 >> CN23XX_PKT_MAC_CTL_RINFO_TRS_BIT_POS) & 0xff;
1184+
if (trs == 1) {
1185+
dev_err(&oct->pci_dev->dev,
1186+
"OCTEON: error reading PCI cfg space pfnum, re-read %u\n",
1187+
pfnum);
1188+
oct->pf_num = pfnum;
1189+
ret = 0;
1190+
} else {
1191+
dev_err(&oct->pci_dev->dev,
1192+
"OCTEON: error reading PCI cfg space pfnum; could not ascertain PF number\n");
1193+
}
1194+
}
1195+
1196+
return ret;
11611197
}
11621198

11631199
static void cn23xx_setup_reg_address(struct octeon_device *oct)
@@ -1279,7 +1315,8 @@ int setup_cn23xx_octeon_pf_device(struct octeon_device *oct)
12791315
return 1;
12801316
}
12811317

1282-
cn23xx_get_pf_num(oct);
1318+
if (cn23xx_get_pf_num(oct) != 0)
1319+
return 1;
12831320

12841321
if (cn23xx_sriov_config(oct)) {
12851322
octeon_unmap_pci_barx(oct, 0);

drivers/net/ethernet/cavium/liquidio/lio_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,8 @@ static int octeon_chip_specific_setup(struct octeon_device *oct)
15601560
case OCTEON_CN23XX_PCIID_PF:
15611561
oct->chip_id = OCTEON_CN23XX_PF_VID;
15621562
ret = setup_cn23xx_octeon_pf_device(oct);
1563+
if (ret)
1564+
break;
15631565
#ifdef CONFIG_PCI_IOV
15641566
if (!ret)
15651567
pci_sriov_set_totalvfs(oct->pci_dev,

0 commit comments

Comments
 (0)