@@ -4744,7 +4744,7 @@ int pcie_retrain_link(struct pci_dev *pdev, bool use_lt)
47444744 * to track link speed or width changes made by hardware itself
47454745 * in attempt to correct unreliable link operation.
47464746 */
4747- pcie_capability_write_word (pdev , PCI_EXP_LNKSTA , PCI_EXP_LNKSTA_LBMS );
4747+ pcie_reset_lbms_count (pdev );
47484748 return rc ;
47494749}
47504750
@@ -6193,38 +6193,66 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
61936193EXPORT_SYMBOL (pcie_bandwidth_available );
61946194
61956195/**
6196- * pcie_get_speed_cap - query for the PCI device's link speed capability
6196+ * pcie_get_supported_speeds - query Supported Link Speed Vector
61976197 * @dev: PCI device to query
61986198 *
6199- * Query the PCI device speed capability. Return the maximum link speed
6200- * supported by the device.
6199+ * Query @dev supported link speeds.
6200+ *
6201+ * Implementation Note in PCIe r6.0 sec 7.5.3.18 recommends determining
6202+ * supported link speeds using the Supported Link Speeds Vector in the Link
6203+ * Capabilities 2 Register (when available).
6204+ *
6205+ * Link Capabilities 2 was added in PCIe r3.0, sec 7.8.18.
6206+ *
6207+ * Without Link Capabilities 2, i.e., prior to PCIe r3.0, Supported Link
6208+ * Speeds field in Link Capabilities is used and only 2.5 GT/s and 5.0 GT/s
6209+ * speeds were defined.
6210+ *
6211+ * For @dev without Supported Link Speed Vector, the field is synthesized
6212+ * from the Max Link Speed field in the Link Capabilities Register.
6213+ *
6214+ * Return: Supported Link Speeds Vector (+ reserved 0 at LSB).
62016215 */
6202- enum pci_bus_speed pcie_get_speed_cap (struct pci_dev * dev )
6216+ u8 pcie_get_supported_speeds (struct pci_dev * dev )
62036217{
62046218 u32 lnkcap2 , lnkcap ;
6219+ u8 speeds ;
62056220
62066221 /*
6207- * Link Capabilities 2 was added in PCIe r3.0, sec 7.8.18. The
6208- * implementation note there recommends using the Supported Link
6209- * Speeds Vector in Link Capabilities 2 when supported.
6210- *
6211- * Without Link Capabilities 2, i.e., prior to PCIe r3.0, software
6212- * should use the Supported Link Speeds field in Link Capabilities,
6213- * where only 2.5 GT/s and 5.0 GT/s speeds were defined.
6222+ * Speeds retain the reserved 0 at LSB before PCIe Supported Link
6223+ * Speeds Vector to allow using SLS Vector bit defines directly.
62146224 */
62156225 pcie_capability_read_dword (dev , PCI_EXP_LNKCAP2 , & lnkcap2 );
6226+ speeds = lnkcap2 & PCI_EXP_LNKCAP2_SLS ;
6227+
6228+ /* Ignore speeds higher than Max Link Speed */
6229+ pcie_capability_read_dword (dev , PCI_EXP_LNKCAP , & lnkcap );
6230+ speeds &= GENMASK (lnkcap & PCI_EXP_LNKCAP_SLS , 0 );
62166231
62176232 /* PCIe r3.0-compliant */
6218- if (lnkcap2 )
6219- return PCIE_LNKCAP2_SLS2SPEED ( lnkcap2 ) ;
6233+ if (speeds )
6234+ return speeds ;
62206235
6221- pcie_capability_read_dword ( dev , PCI_EXP_LNKCAP , & lnkcap );
6236+ /* Synthesize from the Max Link Speed field */
62226237 if ((lnkcap & PCI_EXP_LNKCAP_SLS ) == PCI_EXP_LNKCAP_SLS_5_0GB )
6223- return PCIE_SPEED_5_0GT ;
6238+ speeds = PCI_EXP_LNKCAP2_SLS_5_0GB | PCI_EXP_LNKCAP2_SLS_2_5GB ;
62246239 else if ((lnkcap & PCI_EXP_LNKCAP_SLS ) == PCI_EXP_LNKCAP_SLS_2_5GB )
6225- return PCIE_SPEED_2_5GT ;
6240+ speeds = PCI_EXP_LNKCAP2_SLS_2_5GB ;
6241+
6242+ return speeds ;
6243+ }
62266244
6227- return PCI_SPEED_UNKNOWN ;
6245+ /**
6246+ * pcie_get_speed_cap - query for the PCI device's link speed capability
6247+ * @dev: PCI device to query
6248+ *
6249+ * Query the PCI device speed capability.
6250+ *
6251+ * Return: the maximum link speed supported by the device.
6252+ */
6253+ enum pci_bus_speed pcie_get_speed_cap (struct pci_dev * dev )
6254+ {
6255+ return PCIE_LNKCAP2_SLS2SPEED (dev -> supported_speeds );
62286256}
62296257EXPORT_SYMBOL (pcie_get_speed_cap );
62306258
0 commit comments