Skip to contentSkip to conversation

PCI: dwc: Round up num_ctrls if num_vectors is less than MAX_MSI_IRQS_PER_CTRL

PATCH RESEND In review Shawn Lin 4 participants 5 messages Nov 22, 2022 – Apr 5, 2023

Subsystems (4)
lore
Share & tools
lore

Shawn Lin

author
#0 lore raw

PATCH RESEND v2 1/1 PCI: dwc: Round up num_ctrls if num_vectors is less than MAX_MSI_IRQS_PER_CTRL

Some SoCs may only support 1 RC with a few MSIs support that the total number of MSIs is less than MAX_MSI_IRQS_PER_CTRL. In this case, num_ctrls will be zero which fails setting up MSI support. Fix it by rounding up num_ctrls to at least one.

---

Changes in v2:
- set num_ctrls to 1 if it's less than one

 drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -0
index 39f3b37..cfce1e0 100644
@@ -62,6 +62,8 @@ irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp)
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 
 	num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+	if (num_ctrls < 1)
+		num_ctrls = 1;
 
 	for (i = 0; i < num_ctrls; i++) {
 		status = dw_pcie_readl_dbi(pci, PCIE_MSI_INTR0_STATUS +
@@ -343,6 +345,8 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
 	if (!pp->num_vectors)
 		pp->num_vectors = MSI_DEF_NUM_VECTORS;
 	num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+	if (num_ctrls < 1)
+		num_ctrls = 1;
 
 	if (!pp->msi_irq[0]) {
 		pp->msi_irq[0] = platform_get_irq_byname_optional(pdev, "msi");
@@ -707,6 +711,8 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
 
 	if (pp->has_msi_ctrl) {
 		num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+		if (num_ctrls < 1)
+			num_ctrls = 1;
 
 		/* Initialize IRQ Status array */
 		for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
Signature · 1 line
2.7.4
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 6 lines · On Mon, Nov 21, 2022 Shawn Lin <[email protected]> wrote:

Some SoCs may only support 1 RC with a few MSIs support that the total number of MSIs is less than MAX_MSI_IRQS_PER_CTRL. In this case, num_ctrls will be zero which fails setting up MSI support. Fix it by rounding up num_ctrls to at least one.

Best regards,
Jingoo Han

Quoted 42 lines

---

Changes in v2:
- set num_ctrls to 1 if it's less than one

 drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -1
index 39f3b37..cfce1e0 100644
@@ -62,6 +62,8 @@ irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp)
        struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 
        num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+       if (num_ctrls < 1)
+               num_ctrls = 1;
 
        for (i = 0; i < num_ctrls; i++) {
                status = dw_pcie_readl_dbi(pci, PCIE_MSI_INTR0_STATUS +
@@ -343,6 +345,8 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
        if (!pp->num_vectors)
                pp->num_vectors = MSI_DEF_NUM_VECTORS;
        num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+       if (num_ctrls < 1)
+               num_ctrls = 1;
 
        if (!pp->msi_irq[0]) {
                pp->msi_irq[0] = platform_get_irq_byname_optional(pdev, "msi");
@@ -707,6 +711,8 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
 
        if (pp->has_msi_ctrl) {
                num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+               if (num_ctrls < 1)
+                       num_ctrls = 1;
 
                /* Initialize IRQ Status array */
                for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
--

2.7.4

author
#2 lore raw
Quoted 9 lines · Han Jingoo
Quoted 6 lines · On Mon, Nov 21, 2022 Shawn Lin <[email protected]> wrote:

Some SoCs may only support 1 RC with a few MSIs support that the total number of MSIs is less than MAX_MSI_IRQS_PER_CTRL. In this case, num_ctrls will be zero which fails setting up MSI support. Fix it by rounding up num_ctrls to at least one.

Thanks, Jingoo!

Hi Lorenzo,

Is there any chance this patch be applied? :)

Quoted 41 lines

Best regards,
Jingoo Han

Quoted 37 lines

---

Changes in v2:
- set num_ctrls to 1 if it's less than one

  drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -0
index 39f3b37..cfce1e0 100644
@@ -62,6 +62,8 @@ irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp)
         struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 
         num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+       if (num_ctrls < 1)
+               num_ctrls = 1;
 
         for (i = 0; i < num_ctrls; i++) {
                 status = dw_pcie_readl_dbi(pci, PCIE_MSI_INTR0_STATUS +
@@ -343,6 +345,8 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
         if (!pp->num_vectors)
                 pp->num_vectors = MSI_DEF_NUM_VECTORS;
         num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+       if (num_ctrls < 1)
+               num_ctrls = 1;
 
         if (!pp->msi_irq[0]) {
                 pp->msi_irq[0] = platform_get_irq_byname_optional(pdev, "msi");
@@ -707,6 +711,8 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
 
         if (pp->has_msi_ctrl) {
                 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+               if (num_ctrls < 1)
+                       num_ctrls = 1;
 
Quoted 5 lines
Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-host.c +0 -1
                 /* Initialize IRQ Status array */
                 for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
--

2.7.4

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#3 lore raw
Quoted 29 lines · Shawn Lin
Quoted 9 lines · Han Jingoo
Quoted 6 lines · On Mon, Nov 21, 2022 Shawn Lin <[email protected]> wrote:

Some SoCs may only support 1 RC with a few MSIs support that the total number of MSIs is less than MAX_MSI_IRQS_PER_CTRL. In this case, num_ctrls will be zero which fails setting up MSI support. Fix it by rounding up num_ctrls to at least one.

Thanks, Jingoo!

Hi Lorenzo,

Is there any chance this patch be applied? :)

Quoted 12 lines

Best regards,
Jingoo Han

Quoted 8 lines

---

Changes in v2:
- set num_ctrls to 1 if it's less than one

  drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++++++
  1 file changed, 6 insertions(+)
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pcie-designware-host.c irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp) · line 64

Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-host.c +0 -0
index 39f3b37..cfce1e0 100644
@@ -62,6 +62,8 @@ irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp)
         struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 
         num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;

I assume that if pp->num_vectors > MAX_MSI_IRQS_PER_CTRL but not an exact multiple we would have the same problem right ?

Best to fix it for both cases.

Lorenzo

Quoted 31 lines
Quoted 21 lines
Quoted 21 lines
drivers/pci/controller/dwc/pcie-designware-host.c +6 -0
+       if (num_ctrls < 1)
+               num_ctrls = 1;
 
         for (i = 0; i < num_ctrls; i++) {
                 status = dw_pcie_readl_dbi(pci, PCIE_MSI_INTR0_STATUS +
@@ -343,6 +345,8 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
         if (!pp->num_vectors)
                 pp->num_vectors = MSI_DEF_NUM_VECTORS;
         num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+       if (num_ctrls < 1)
+               num_ctrls = 1;
 
         if (!pp->msi_irq[0]) {
                 pp->msi_irq[0] = platform_get_irq_byname_optional(pdev, "msi");
@@ -707,6 +711,8 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
 
         if (pp->has_msi_ctrl) {
                 num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
+               if (num_ctrls < 1)
+                       num_ctrls = 1;
 
Quoted 5 lines
Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-host.c +0 -1
                 /* Initialize IRQ Status array */
                 for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
--

2.7.4

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#4 lore raw
In reply to Shawn Lin
Quoted 2 lines · Shawn Lin

Some SoCs may only support 1 RC with a few MSIs support that the total number of MSIs is less than MAX_MSI_IRQS_PER_CTRL.

I'm not quite sure what this sentence says. Maybe it should be split into two sentences?

Quoted 2 lines

In this case, num_ctrls will be zero which fails setting up MSI support. Fix it by rounding up num_ctrls to at least one.

If you have occasion to repost, please rewrap the commit log to fit in 75 columns.

Krzysztof or Lorenzo will likely fix this when applying otherwise.

Bjorn