diff mbox series

[next,V4,8/8] net/mlx5e: Use generic PCI function for bandwidth calculation

Message ID 1522394086-3555-9-git-send-email-talgi@mellanox.com
State Not Applicable
Headers show
Series Report PCI device link status | expand

Commit Message

Tal Gilboa March 30, 2018, 7:14 a.m. UTC
Newly introduced pci_bandwidth_available() function calculates
maximum available bandwidth through the PCI chain. We can use this
value for mlx5e_get_pci_bw() instead of calculating ourselves.
This is mainly used for detecting cases on which PCIe bandwidth
can't support current link speed and the driver need to act accordingly.
By taking PCIe encoding into account, this calculation is even more
accurate.

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 4a675f1..fc51a73 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -4011,27 +4011,16 @@  static int mlx5e_get_pci_bw(struct mlx5_core_dev *mdev, u32 *pci_bw)
 	enum pcie_link_width width;
 	enum pci_bus_speed speed;
 	int err = 0;
+	int bw;
 
-	err = pcie_get_minimum_link(mdev->pdev, &speed, &width);
+	err = pcie_bandwidth_available(mdev->pdev, &speed, &width, &bw, NULL);
 	if (err)
 		return err;
 
 	if (speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
 		return -EINVAL;
 
-	switch (speed) {
-	case PCIE_SPEED_2_5GT:
-		*pci_bw = 2500 * width;
-		break;
-	case PCIE_SPEED_5_0GT:
-		*pci_bw = 5000 * width;
-		break;
-	case PCIE_SPEED_8_0GT:
-		*pci_bw = 8000 * width;
-		break;
-	default:
-		return -EINVAL;
-	}
+	*pci_bw = bw;
 
 	return 0;
 }