|
@@ -5146,6 +5146,64 @@ int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed,
|
|
|
}
|
|
|
EXPORT_SYMBOL(pcie_get_minimum_link);
|
|
|
|
|
|
+/**
|
|
|
+ * pcie_bandwidth_available - determine minimum link settings of a PCIe
|
|
|
+ * device and its bandwidth limitation
|
|
|
+ * @dev: PCI device to query
|
|
|
+ * @limiting_dev: storage for device causing the bandwidth limitation
|
|
|
+ * @speed: storage for speed of limiting device
|
|
|
+ * @width: storage for width of limiting device
|
|
|
+ *
|
|
|
+ * Walk up the PCI device chain and find the point where the minimum
|
|
|
+ * bandwidth is available. Return the bandwidth available there and (if
|
|
|
+ * limiting_dev, speed, and width pointers are supplied) information about
|
|
|
+ * that point. The bandwidth returned is in Mb/s, i.e., megabits/second of
|
|
|
+ * raw bandwidth.
|
|
|
+ */
|
|
|
+u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
|
|
|
+ enum pci_bus_speed *speed,
|
|
|
+ enum pcie_link_width *width)
|
|
|
+{
|
|
|
+ u16 lnksta;
|
|
|
+ enum pci_bus_speed next_speed;
|
|
|
+ enum pcie_link_width next_width;
|
|
|
+ u32 bw, next_bw;
|
|
|
+
|
|
|
+ if (speed)
|
|
|
+ *speed = PCI_SPEED_UNKNOWN;
|
|
|
+ if (width)
|
|
|
+ *width = PCIE_LNK_WIDTH_UNKNOWN;
|
|
|
+
|
|
|
+ bw = 0;
|
|
|
+
|
|
|
+ while (dev) {
|
|
|
+ pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
|
|
|
+
|
|
|
+ next_speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS];
|
|
|
+ next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >>
|
|
|
+ PCI_EXP_LNKSTA_NLW_SHIFT;
|
|
|
+
|
|
|
+ next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
|
|
|
+
|
|
|
+ /* Check if current device limits the total bandwidth */
|
|
|
+ if (!bw || next_bw <= bw) {
|
|
|
+ bw = next_bw;
|
|
|
+
|
|
|
+ if (limiting_dev)
|
|
|
+ *limiting_dev = dev;
|
|
|
+ if (speed)
|
|
|
+ *speed = next_speed;
|
|
|
+ if (width)
|
|
|
+ *width = next_width;
|
|
|
+ }
|
|
|
+
|
|
|
+ dev = pci_upstream_bridge(dev);
|
|
|
+ }
|
|
|
+
|
|
|
+ return bw;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(pcie_bandwidth_available);
|
|
|
+
|
|
|
/**
|
|
|
* pcie_get_speed_cap - query for the PCI device's link speed capability
|
|
|
* @dev: PCI device to query
|