2018-12-13 06:23:30

by Richard Zhu

[permalink] [raw]
Subject: [PATCH] PCI: imx: make msi work without pcieportbus

MSI_EN of iMX PCIe RC would be asserted when
PCIEPORTBUS driver is selected.
Thus, the MSI works fine on iMX PCIe before.
Make a double check on this bit, and assert it
when it is not set and MSI is supported.
Otherwise, the MSI wouldn't be triggered although
the EP is present and the MSIs are assigned.

Signed-off-by: Richard Zhu <[email protected]>
---
drivers/pci/controller/dwc/pci-imx6.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 26087b3..6c3e56b 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -74,6 +74,7 @@ struct imx6_pcie {
#define PHY_PLL_LOCK_WAIT_USLEEP_MAX 200

/* PCIe Root Complex registers (memory-mapped) */
+#define PCI_MSI_CAP 0x50
#define PCIE_RC_LCR 0x7c
#define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1 0x1
#define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2 0x2
@@ -926,6 +927,7 @@ static int imx6_pcie_probe(struct platform_device *pdev)
struct resource *dbi_base;
struct device_node *node = dev->of_node;
int ret;
+ u16 val;

imx6_pcie = devm_kzalloc(dev, sizeof(*imx6_pcie), GFP_KERNEL);
if (!imx6_pcie)
@@ -1070,6 +1072,14 @@ static int imx6_pcie_probe(struct platform_device *pdev)
ret = imx6_add_pcie_port(imx6_pcie, pdev);
if (ret < 0)
return ret;
+ if (IS_ENABLED(CONFIG_PCI_MSI)) {
+ val = dw_pcie_readw_dbi(pci, PCI_MSI_CAP + PCI_MSI_FLAGS);
+ if ((val & PCI_MSI_FLAGS_ENABLE) == 0) {
+ val |= PCI_MSI_FLAGS_ENABLE;
+ dw_pcie_writew_dbi(pci, PCI_MSI_CAP +
+ PCI_MSI_FLAGS, val);
+ }
+ }

return 0;
}
--
2.7.4



2018-12-13 06:59:12

by Baruch Siach

[permalink] [raw]
Subject: Re: [PATCH] PCI: imx: make msi work without pcieportbus

Hi Richard,

Thanks for debugging this issue. One question below.

Richard Zhu writes:
> MSI_EN of iMX PCIe RC would be asserted when
> PCIEPORTBUS driver is selected.
> Thus, the MSI works fine on iMX PCIe before.
> Make a double check on this bit, and assert it
> when it is not set and MSI is supported.
> Otherwise, the MSI wouldn't be triggered although
> the EP is present and the MSIs are assigned.
>
> Signed-off-by: Richard Zhu <[email protected]>
> ---
> drivers/pci/controller/dwc/pci-imx6.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 26087b3..6c3e56b 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -74,6 +74,7 @@ struct imx6_pcie {
> #define PHY_PLL_LOCK_WAIT_USLEEP_MAX 200
>
> /* PCIe Root Complex registers (memory-mapped) */
> +#define PCI_MSI_CAP 0x50
> #define PCIE_RC_LCR 0x7c
> #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1 0x1
> #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2 0x2
> @@ -926,6 +927,7 @@ static int imx6_pcie_probe(struct platform_device *pdev)
> struct resource *dbi_base;
> struct device_node *node = dev->of_node;
> int ret;
> + u16 val;
>
> imx6_pcie = devm_kzalloc(dev, sizeof(*imx6_pcie), GFP_KERNEL);
> if (!imx6_pcie)
> @@ -1070,6 +1072,14 @@ static int imx6_pcie_probe(struct platform_device *pdev)
> ret = imx6_add_pcie_port(imx6_pcie, pdev);
> if (ret < 0)
> return ret;
> + if (IS_ENABLED(CONFIG_PCI_MSI)) {
> + val = dw_pcie_readw_dbi(pci, PCI_MSI_CAP + PCI_MSI_FLAGS);
> + if ((val & PCI_MSI_FLAGS_ENABLE) == 0) {
> + val |= PCI_MSI_FLAGS_ENABLE;

Why not assert the PCI_MSI_FLAGS_ENABLE flag unconditionally here?

> + dw_pcie_writew_dbi(pci, PCI_MSI_CAP +
> + PCI_MSI_FLAGS, val);
> + }
> + }
>
> return 0;
> }

baruch

--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.52.368.4656, http://www.tkos.co.il -

2018-12-13 07:23:45

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH] PCI: imx: make msi work without pcieportbus


> -----Original Message-----
> From: Baruch Siach [mailto:[email protected]]
> Sent: 2018??12??13?? 14:37
> To: Richard Zhu <[email protected]>
> Cc: [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]
> Subject: Re: [PATCH] PCI: imx: make msi work without pcieportbus
>
> Hi Richard,
>
> Thanks for debugging this issue. One question below.
>
> Richard Zhu writes:
> > MSI_EN of iMX PCIe RC would be asserted when PCIEPORTBUS driver is
> > selected.
> > Thus, the MSI works fine on iMX PCIe before.
> > Make a double check on this bit, and assert it when it is not set and
> > MSI is supported.
> > Otherwise, the MSI wouldn't be triggered although the EP is present
> > and the MSIs are assigned.
> >
> > Signed-off-by: Richard Zhu <[email protected]>
> > ---
> > drivers/pci/controller/dwc/pci-imx6.c | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > diff --git a/drivers/pci/controller/dwc/pci-imx6.c
> > b/drivers/pci/controller/dwc/pci-imx6.c
> > index 26087b3..6c3e56b 100644
> > --- a/drivers/pci/controller/dwc/pci-imx6.c
> > +++ b/drivers/pci/controller/dwc/pci-imx6.c
> > @@ -74,6 +74,7 @@ struct imx6_pcie {
> > #define PHY_PLL_LOCK_WAIT_USLEEP_MAX 200
> >
> > /* PCIe Root Complex registers (memory-mapped) */
> > +#define PCI_MSI_CAP 0x50
> > #define PCIE_RC_LCR 0x7c
> > #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1 0x1
> > #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2 0x2
> > @@ -926,6 +927,7 @@ static int imx6_pcie_probe(struct platform_device
> *pdev)
> > struct resource *dbi_base;
> > struct device_node *node = dev->of_node;
> > int ret;
> > + u16 val;
> >
> > imx6_pcie = devm_kzalloc(dev, sizeof(*imx6_pcie), GFP_KERNEL);
> > if (!imx6_pcie)
> > @@ -1070,6 +1072,14 @@ static int imx6_pcie_probe(struct
> platform_device *pdev)
> > ret = imx6_add_pcie_port(imx6_pcie, pdev);
> > if (ret < 0)
> > return ret;
> > + if (IS_ENABLED(CONFIG_PCI_MSI)) {
> > + val = dw_pcie_readw_dbi(pci, PCI_MSI_CAP + PCI_MSI_FLAGS);
> > + if ((val & PCI_MSI_FLAGS_ENABLE) == 0) {
> > + val |= PCI_MSI_FLAGS_ENABLE;
>
> Why not assert the PCI_MSI_FLAGS_ENABLE flag unconditionally here?
[Richard Zhu] Thanks for your kindly review.
It's more efficient to set it unconditionally.
I would change it in next version.

>
> > + dw_pcie_writew_dbi(pci, PCI_MSI_CAP +
> > + PCI_MSI_FLAGS, val);
> > + }
> > + }
> >
> > return 0;
> > }
>
> baruch
>
> --
>
> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbaru
> ch.siach.name%2Fblog%2F&amp;data=02%7C01%7Chongxing.zhu%40nxp.co
> m%7Ce9d8a943e90f4055f41708d660c55801%7C686ea1d3bc2b4c6fa92cd99
> c5c301635%7C0%7C0%7C636802798043957806&amp;sdata=hh4ichdPcGA0
> N1om4AdZIOaEX3HE2rpW6jYl8m1F%2FWE%3D&amp;reserved=0
> ~. .~ Tk Open Systems
> =}------------------------------------------------ooO--U--Ooo------------{=
> - [email protected] - tel: +972.52.368.4656,
> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww
> .tkos.co.il&amp;data=02%7C01%7Chongxing.zhu%40nxp.com%7Ce9d8a943e
> 90f4055f41708d660c55801%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0
> %7C0%7C636802798043957806&amp;sdata=awQAaFvN9%2B63IxOonaox7O
> JxZoTtSHJGFNKSXEKPKso%3D&amp;reserved=0 -