Page MenuHomeFreeBSD

D62317.1796364863.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D62317.1796364863.diff

diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -3205,6 +3205,43 @@
return (pci_read_config(dev, PCIR_COMMAND, 2) & PCIM_CMD_MEMEN) != 0;
}
+#ifdef PCI_IOV
+/*
+ * Returns true if register 'reg' of a PF is one of the VF BARs in its
+ * SR-IOV capability.
+ *
+ * VF BARs are decoded under the VF Memory Space Enable bit in the SR-IOV
+ * control register, not under the PF's command register. They are sized
+ * and programmed only by pci_iov_config(), which clears VF Enable and
+ * VF MSE first and sets them again once all VF BARs are programmed, so
+ * nothing decodes a VF BAR while it is written. The PF's driver, however,
+ * is attached and running at that point: clearing the memory enable bit
+ * in the PF's command register would take the PF's own BARs away from it,
+ * making its register reads return all ones and dropping its register
+ * writes. The callers therefore leave the command register alone for
+ * these BARs.
+ */
+static bool
+pci_is_vf_bar(device_t dev, int reg)
+{
+ struct pci_devinfo *dinfo;
+ struct pcicfg_iov *iov;
+
+ dinfo = device_get_ivars(dev);
+ iov = dinfo->cfg.iov;
+ if (iov == NULL || (dinfo->cfg.flags & PCICFG_VF) != 0)
+ return (false);
+ return (reg >= iov->iov_pos + PCIR_SRIOV_BAR(0) &&
+ reg <= iov->iov_pos + PCIR_SRIOV_BAR(PCIR_MAX_BAR_0));
+}
+#else
+static bool
+pci_is_vf_bar(device_t dev __unused, int reg __unused)
+{
+ return (false);
+}
+#endif
+
void
pci_read_bar(device_t dev, int reg, pci_addr_t *mapp, pci_addr_t *testvalp,
int *bar64)
@@ -3213,6 +3250,7 @@
pci_addr_t map, testval;
int ln2range;
uint16_t cmd;
+ bool vf_bar;
/*
* The device ROM BAR is special. It is always a 32-bit
@@ -3240,11 +3278,15 @@
/*
* Disable decoding via the command register before
* determining the BAR's length since we will be placing it in
- * a weird state.
+ * a weird state. The VF BARs of a PF are not decoded here,
+ * see pci_is_vf_bar().
*/
- cmd = pci_read_config(dev, PCIR_COMMAND, 2);
- pci_write_config(dev, PCIR_COMMAND,
- cmd & ~(PCI_BAR_MEM(map) ? PCIM_CMD_MEMEN : PCIM_CMD_PORTEN), 2);
+ vf_bar = pci_is_vf_bar(dev, reg);
+ if (!vf_bar) {
+ cmd = pci_read_config(dev, PCIR_COMMAND, 2);
+ pci_write_config(dev, PCIR_COMMAND, cmd &
+ ~(PCI_BAR_MEM(map) ? PCIM_CMD_MEMEN : PCIM_CMD_PORTEN), 2);
+ }
/*
* Determine the BAR's length by writing all 1's. The bottom
@@ -3274,7 +3316,8 @@
pci_write_config(dev, reg, map, 4);
if (ln2range == 64)
pci_write_config(dev, reg + 4, map >> 32, 4);
- pci_write_config(dev, PCIR_COMMAND, cmd, 2);
+ if (!vf_bar)
+ pci_write_config(dev, PCIR_COMMAND, cmd, 2);
*mapp = map;
*testvalp = testval;
@@ -6113,6 +6156,7 @@
struct resource *res;
struct pci_map *pm;
uint16_t cmd;
+ bool vf_bar;
pci_addr_t map, testval;
int mapsize;
@@ -6203,16 +6247,23 @@
"Lazy allocation of %#jx bytes rid %#x type %d at %#jx\n",
count, rid, type, rman_get_start(res));
- /* Disable decoding via the CMD register before updating the BAR */
- cmd = pci_read_config(child, PCIR_COMMAND, 2);
- pci_write_config(child, PCIR_COMMAND,
- cmd & ~(PCI_BAR_MEM(map) ? PCIM_CMD_MEMEN : PCIM_CMD_PORTEN), 2);
+ /*
+ * Disable decoding via the CMD register before updating the BAR.
+ * The VF BARs of a PF are not decoded here, see pci_is_vf_bar().
+ */
+ vf_bar = pci_is_vf_bar(child, rid);
+ if (!vf_bar) {
+ cmd = pci_read_config(child, PCIR_COMMAND, 2);
+ pci_write_config(child, PCIR_COMMAND, cmd &
+ ~(PCI_BAR_MEM(map) ? PCIM_CMD_MEMEN : PCIM_CMD_PORTEN), 2);
+ }
map = rman_get_start(res);
pci_write_bar(child, pm, map);
/* Restore the original value of the CMD register */
- pci_write_config(child, PCIR_COMMAND, cmd, 2);
+ if (!vf_bar)
+ pci_write_config(child, PCIR_COMMAND, cmd, 2);
out:
return (res);
}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 4, 6:14 AM (23 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42200999
Default Alt Text
D62317.1796364863.diff (3 KB)

Event Timeline