Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178260097
D62317.1796357334.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D62317.1796357334.diff
View Options
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,80 @@
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.
+ */
+static bool
+pci_is_vf_bar(struct pci_devinfo *dinfo, int reg)
+{
+ struct pcicfg_iov *iov;
+
+ 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));
+}
+#endif
+
+/*
+ * Disable decoding of the BAR at register 'reg' before it is sized or
+ * reprogrammed. The return value is passed to pci_restore_bar_decoding()
+ * afterwards.
+ *
+ * The VF BARs in a PF's SR-IOV capability are decoded under the VF Memory
+ * Space Enable bit in the SR-IOV control register, not under the PF's
+ * command register. pci_iov_config() sets them up while the PF's driver
+ * is attached and running, so clearing the memory enable bit in the PF's
+ * command register would only take the PF's own BARs away from that
+ * driver: a register read in that window returns all ones and a register
+ * write is dropped. Leave the command register alone for these BARs and
+ * clear VF MSE instead, if it is set.
+ */
+static uint16_t
+pci_disable_bar_decoding(device_t dev, int reg, pci_addr_t map)
+{
+ uint16_t cmd;
+#ifdef PCI_IOV
+ struct pci_devinfo *dinfo;
+ int ctl;
+
+ dinfo = device_get_ivars(dev);
+ if (pci_is_vf_bar(dinfo, reg)) {
+ ctl = dinfo->cfg.iov->iov_pos + PCIR_SRIOV_CTL;
+ cmd = pci_read_config(dev, ctl, 2);
+ if ((cmd & PCIM_SRIOV_VF_MSE) != 0)
+ pci_write_config(dev, ctl, cmd & ~PCIM_SRIOV_VF_MSE, 2);
+ return (cmd);
+ }
+#endif
+
+ 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);
+ return (cmd);
+}
+
+static void
+pci_restore_bar_decoding(device_t dev, int reg, uint16_t cmd)
+{
+#ifdef PCI_IOV
+ struct pci_devinfo *dinfo;
+
+ dinfo = device_get_ivars(dev);
+ if (pci_is_vf_bar(dinfo, reg)) {
+ if ((cmd & PCIM_SRIOV_VF_MSE) != 0)
+ pci_write_config(dev,
+ dinfo->cfg.iov->iov_pos + PCIR_SRIOV_CTL, cmd, 2);
+ return;
+ }
+#endif
+
+ pci_write_config(dev, PCIR_COMMAND, cmd, 2);
+}
+
void
pci_read_bar(device_t dev, int reg, pci_addr_t *mapp, pci_addr_t *testvalp,
int *bar64)
@@ -3238,13 +3312,10 @@
map |= (pci_addr_t)pci_read_config(dev, reg + 4, 4) << 32;
/*
- * Disable decoding via the command register before
- * determining the BAR's length since we will be placing it in
- * a weird state.
+ * Disable decoding before determining the BAR's length since we
+ * will be placing it in a weird state.
*/
- 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);
+ cmd = pci_disable_bar_decoding(dev, reg, map);
/*
* Determine the BAR's length by writing all 1's. The bottom
@@ -3274,7 +3345,7 @@
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);
+ pci_restore_bar_decoding(dev, reg, cmd);
*mapp = map;
*testvalp = testval;
@@ -6203,16 +6274,13 @@
"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 before updating the BAR */
+ cmd = pci_disable_bar_decoding(child, rid, map);
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);
+ pci_restore_bar_decoding(child, rid, cmd);
out:
return (res);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 4, 4:08 AM (22 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42181464
Default Alt Text
D62317.1796357334.diff (3 KB)
Attached To
Mode
D62317: pci: Do not turn off a PF's memory decoding to set up its VF BARs
Attached
Detach File
Event Timeline