Skip to contentSkip to conversation

PCI: dwc-host: Add a warning to prevent invalid values

PATCH In review JunDong Song 2 participants 3 messages Nov 7, 2022 – Nov 10, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 PCI: dwc-host: Add a warning to prevent invalid values

of_pci_get_max_link_speed() may return a negative value, causing the controller to not set the speed correctly. Add a warning in case the driver engineer misses it.

---

When I use the pcie dwc driver, the controller speed is abnormal, but it has not been detected because of the @max-link-speed error, so I think I need to return an error or warning here.

Thanks.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -1
index 83ddb1902..573342601 100644
@@ -739,8 +739,11 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 		return -ENOMEM;
 	ep->outbound_addr = addr;
 
-	if (pci->link_gen < 1)
+	if (pci->link_gen < 1) {
 		pci->link_gen = of_pci_get_max_link_speed(np);
+		if (unlikely(pci->link_gen < 0))
+			dev_warn(dev, "Failed to get max link speed\n");
+	}
 
 	epc = devm_pci_epc_create(dev, &epc_ops);
 	if (IS_ERR(epc)) {
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 PCI: dwc-host: Add a warning to prevent invalid values

of_pci_get_max_link_speed() may return a negative value, causing the controller to not set the speed correctly. Add a warning in case the driver engineer misses it.

---

When I use the pcie dwc driver, the controller speed is abnormal, but it has not been detected because of the @max-link-speed error, so I think I need to return an error or warning here.

Thanks.

 drivers/pci/controller/dwc/pcie-designware-host.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +4 -1
index 39f3b37d4..0103b9a63 100644
@@ -429,8 +429,11 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
 		pp->io_base = pci_pio_to_address(win->res->start);
 	}
 
-	if (pci->link_gen < 1)
+	if (pci->link_gen < 1) {
 		pci->link_gen = of_pci_get_max_link_speed(np);
+		if (unlikely(pci->link_gen < 0))
+			dev_warn(dev, "Failed to get max link speed\n");
+	}
 
 	/* Set default bus ops */
 	bridge->ops = &dw_pcie_ops;
Signature · 1 line
2.25.1
#2 lore raw
In reply to JunDong Song

The subject lines are not quite accurate. The warning does nothing to *prevent* invalid values; it only warns about them.

And it should say what *kind* of values we're talking about.

Maybe:

PCI: dwc: Warn about invalid 'max-link-speed' from DT

Quoted 3 lines · JunDong Song

of_pci_get_max_link_speed() may return a negative value, causing the controller to not set the speed correctly. Add a warning in case the driver engineer misses it.

Rewrap this to fill 75 columns.

I would probably squash these into a single patch since they're doing exactly the same thing to the host and endpoint cases.

Quoted 17 lines

---

When I use the pcie dwc driver, the controller speed is abnormal, but it has not been detected because of the @max-link-speed error, so I think I need to return an error or warning here.

Thanks.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
index 83ddb1902..573342601 100644

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_init(struct dw_pcie_ep *ep) · line 744

Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +2 -1
@@ -739,8 +739,11 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 		return -ENOMEM;
 	ep->outbound_addr = addr;
 
-	if (pci->link_gen < 1)
+	if (pci->link_gen < 1) {
 		pci->link_gen = of_pci_get_max_link_speed(np);
+		if (unlikely(pci->link_gen < 0))

Using "unlikely" here is unnecessary since this is not a performance path, and it's a distraction.

Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +2 -0
+			dev_warn(dev, "Failed to get max link speed\n");
+	}
 
 	epc = devm_pci_epc_create(dev, &epc_ops);
 	if (IS_ERR(epc)) {
Signature · 1 line
2.25.1