Commit Graph

48 Commits

Author SHA1 Message Date
Myron Stowe 3cab5b8073 PCI: mediatek: Drop excess mtk_pcie.mem kerneldoc description
JIRA: https://issues.redhat.com/browse/RHEL-67693
Upstream Status: dd9d80408b7d6041ebaf2346c66d258bf6adceae

commit dd9d80408b7d6041ebaf2346c66d258bf6adceae
Author: Bjorn Helgaas <bhelgaas@google.com>
Date:   Tue Sep 3 15:16:13 2024 -0500

    PCI: mediatek: Drop excess mtk_pcie.mem kerneldoc description

    Struct mtk_pcie.mem was removed by 8a26f861b8 ("PCI: mediatek: Use
    pci_parse_request_of_pci_ranges()"), but the kerneldoc was left.  Remove
    the extra kerneldoc.

    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2025-02-18 09:48:09 -07:00
Myron Stowe 23af034207 PCI: mediatek: Silence 'set affinity failed' warning
JIRA: https://issues.redhat.com/browse/RHEL-67693
Upstream Status: 63e4794cde79c2724f9c02abe8a46be70a5b90df

commit 63e4794cde79c2724f9c02abe8a46be70a5b90df
Author: Marek Vasut <marek.vasut+renesas@mailbox.org>
Date:   Tue Jul 23 15:27:07 2024 +0200

    PCI: mediatek: Silence 'set affinity failed' warning

    Use MSI_FLAG_NO_AFFINITY, which keeps .irq_set_affinity() unset and allows
    migrate_one_irq() to exit right away, without warnings like this:

      IRQ...: set affinity failed(-22)

    Remove the .irq_set_affinity() implementation that is no longer needed.

    Link: https://lore.kernel.org/r/20240723132958.41320-8-marek.vasut+renesas@mailbox.org
    Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
    [bhelgaas: commit log]
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
    Acked-by: Jianjun Wang <jianjun.wang@mediatek.com>
    Acked-by: Thomas Gleixner <tglx@linutronix.de>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2025-02-18 09:48:09 -07:00
Myron Stowe 807fca8e7a PCI: controller: Add missing MODULE_DESCRIPTION() macros
JIRA: https://issues.redhat.com/browse/RHEL-59033
Upstream Status: 142a41da39d1467b7ff7dad64fc421249d06565d

Conflict(s):
  RHEL does not have the following files, thus their respective patch
  hunk was skipped:
    drivers/pci/controller/pcie-apple.c


commit 142a41da39d1467b7ff7dad64fc421249d06565d
Author: Jeff Johnson <quic_jjohnson@quicinc.com>
Date:   Wed Jun 26 10:07:01 2024 -0700

    PCI: controller: Add missing MODULE_DESCRIPTION() macros

    When ARCH=x86, make allmodconfig && make W=1 C=1 reports:

      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/dwc/pci-exynos.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/pci-host-generic.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/pcie-altera.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/pcie-altera-msi.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/pcie-mediatek.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/pcie-mediatek-gen3.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/vmd.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/pcie-apple.o
      WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pci/controller/pcie-mt7621.o

    Add the missing MODULE_DESCRIPTION() macro.

    [kwilczynski: update MODULE_DESCRIPTION() text, commit log]
    Link: https://lore.kernel.org/linux-pci/20240626-md-drivers-pci-controller-v2-1-94c811db7a51@quicinc.com
    Signed-off-by: Jeff Johnson <quic_jjohnson@quicinc.com>
    Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
    Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
    Acked-by: Nirmal Patel <nirmal.patel@linux.intel.com>
    Acked-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> # MT7621

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2024-10-05 10:59:20 -06:00
Myron Stowe dbcb1b1f07 PCI: Use of_property_present() for testing DT property presence
JIRA: https://issues.redhat.com/browse/RHEL-59033
Upstream Status: 9195ee1a1f76033eccb424b97ee647625b7af096

commit 9195ee1a1f76033eccb424b97ee647625b7af096
Author: Rob Herring <robh@kernel.org>
Date:   Fri Mar 10 08:47:19 2023 -0600

    PCI: Use of_property_present() for testing DT property presence

    It is preferred to use typed property access functions (i.e.
    of_property_read_<type> functions) rather than low-level
    of_get_property()/of_find_property() functions for reading properties. As
    part of this, convert of_get_property()/of_find_property() calls to the
    recently added of_property_present() helper when we just want to test for
    presence of a property and nothing more.

    Link: https://lore.kernel.org/r/20230310144719.1544443-1-robh@kernel.org
    Signed-off-by: Rob Herring <robh@kernel.org>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>  # pcie-mediatek

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2024-10-01 11:50:40 -06:00
Myron Stowe 71652e9d83 PCI: mediatek: Clear interrupt status before dispatching handler
JIRA: https://issues.redhat.com/browse/RHEL-28627
Upstream Status: 4e11c29873a8a296a20f99b3e03095e65ebf897d

commit 4e11c29873a8a296a20f99b3e03095e65ebf897d
Author: qizhong cheng <qizhong.cheng@mediatek.com>
Date:   Mon Dec 11 17:49:23 2023 +0800

    PCI: mediatek: Clear interrupt status before dispatching handler

    We found a failure when using the iperf tool during WiFi performance
    testing, where some MSIs were received while clearing the interrupt
    status, and these MSIs cannot be serviced.

    The interrupt status can be cleared even if the MSI status remains pending.
    As such, given the edge-triggered interrupt type, its status should be
    cleared before being dispatched to the handler of the underling device.

    [kwilczynski: commit log, code comment wording]
    Link: https://lore.kernel.org/linux-pci/20231211094923.31967-1-jianjun.wang@mediatek.com
    Fixes: 43e6409db6 ("PCI: mediatek: Add MSI support for MT2712 and MT7622")
    Signed-off-by: qizhong cheng <qizhong.cheng@mediatek.com>
    Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com>
    Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
    [bhelgaas: rewrap comment]
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
    Cc:  <stable@vger.kernel.org>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2024-03-30 14:55:37 -06:00
Myron Stowe ab51bc314e PCI: mediatek: Convert to platform remove callback returning void
JIRA: https://issues.redhat.com/browse/RHEL-2570
Upstream Status: 5e0005409427ec7ca988c6315ebf746f8fb24139

commit 5e0005409427ec7ca988c6315ebf746f8fb24139
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Tue Mar 21 20:32:02 2023 +0100

    PCI: mediatek: Convert to platform remove callback returning void

    The .remove() callback for a platform driver returns an int which makes
    many driver authors wrongly assume it's possible to do error handling by
    returning an error code. However the value returned is (mostly) ignored
    and this typically results in resource leaks. To improve here there is a
    quest to make the remove callback return void. In the first step of this
    quest all drivers are converted to .remove_new() which already returns
    void.

    Trivially convert this driver from always returning zero in the remove
    callback to the void returning variant.

    Link: https://lore.kernel.org/linux-pci/20230321193208.366561-10-u.kleine-koenig@pengutronix.de
    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2023-09-19 13:32:23 -06:00
Myron Stowe 9697a3402c PCI: Convert to new *_PM_OPS macros
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2124638
Upstream Status: 19b7858c3357df038d896c10e0d5e4572a77dd25

commit 19b7858c3357df038d896c10e0d5e4572a77dd25
Author: Bjorn Helgaas <bhelgaas@google.com>
Date:   Tue Jul 19 16:13:25 2022 -0500

    PCI: Convert to new *_PM_OPS macros

    Replace SET_*_PM_OPS with *_PM_OPS, which which have the advantage that the
    compiler always sees the PM callbacks as referenced, so they don't need to
    be wrapped with "#ifdef CONFIG_PM_SLEEP" or tagged with "__maybe_unused" to
    avoid "defined but not used" warnings.

    See 1a3c7bb08826 ("PM: core: Add new *_PM_OPS macros, deprecate old ones").

    Link: https://lore.kernel.org/r/20220719215108.1583108-1-helgaas@kernel.org
    Tested-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Pali Rohár <pali@kernel.org>       # pci-mvebu.c
    Reviewed-by: Arnd Bergmann <arnd@arndb.de>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-10-02 09:36:13 -06:00
Myron Stowe 1809bfad72 PCI: mediatek: Fix refcount leak in mtk_pcie_subsys_powerup()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2118429
Upstream Status: 214e0d8fe4a813ae6ffd62bc2dfe7544c20914f4

commit 214e0d8fe4a813ae6ffd62bc2dfe7544c20914f4
Author: Miaoqian Lin <linmq006@gmail.com>
Date:   Wed Mar 9 09:19:52 2022 +0000

    PCI: mediatek: Fix refcount leak in mtk_pcie_subsys_powerup()

    The of_find_compatible_node() function returns a node pointer with
    refcount incremented, We should use of_node_put() on it when done
    Add the missing of_node_put() to release the refcount.

    Link: https://lore.kernel.org/r/20220309091953.5630-1-linmq006@gmail.com
    Fixes: 87e8657ba99c ("PCI: mediatek: Add new method to get shared pcie-cfg base address")
    Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
    Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
    Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
    Reviewed-by: Miles Chen <miles.chen@mediatek.com>
    Acked-by: Rob Herring <robh@kernel.org>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-09-09 19:29:17 -06:00
Myron Stowe cc757cff5e PCI: mediatek: Drop error data fabrication when config read fails
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2066898
Upstream Status: 7e9768539eb32e0fb5eb09f033b33dbd8a15e16d

commit 7e9768539eb32e0fb5eb09f033b33dbd8a15e16d
Author: Naveen Naidu <naveennaidu479@gmail.com>
Date:   Thu Nov 18 19:33:17 2021 +0530

    PCI: mediatek: Drop error data fabrication when config read fails

    If config pci_ops.read() methods return failure, the PCI_OP_READ() and
    PCI_USER_READ_CONFIG() wrappers use PCI_SET_ERROR_RESPONSE() to set the
    data value, so there's no need to set it in the pci_ops.read() methods
    themselves.

    Drop the unnecessary data value fabrication when pci_ops.read() fails.

    Link: https://lore.kernel.org/r/666127469482f9ca177805ff52aeb7bccb26e4c9.1637243717.git.naveennaidu479@gmail.com
    Signed-off-by: Naveen Naidu <naveennaidu479@gmail.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-04-20 10:14:04 -06:00
Myron Stowe 62cea797e9 PCI: mediatek: Assert PERST# for 100ms for power and clock to stabilize
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2066898
Upstream Status: 65ace9a85fa7f88aec4d9d842061108161fa47bc

commit 65ace9a85fa7f88aec4d9d842061108161fa47bc
Author: qizhong cheng <qizhong.cheng@mediatek.com>
Date:   Mon Dec 27 21:31:10 2021 +0800

    PCI: mediatek: Assert PERST# for 100ms for power and clock to stabilize

    Described in PCIe CEM specification sections 2.2 (PERST# Signal) and
    2.2.1 (Initial Power-Up (G3 to S0)). The deassertion of PERST# should
    be delayed 100ms (TPVPERL) for the power and clock to become stable.

    Link: https://lore.kernel.org/r/20211227133110.14500-1-qizhong.cheng@mediatek.com
    Signed-off-by: qizhong cheng <qizhong.cheng@mediatek.com>
    Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
    Acked-by: Pali Rohár <pali@kernel.org>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-04-20 10:13:55 -06:00
Myron Stowe f0558ecb6f PCI: mediatek: Use PCI domain to handle ports detection
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2045254
Upstream Status: 77216702c8f6288f948ee230772b4612b835c5d6

commit 77216702c8f6288f948ee230772b4612b835c5d6
Author: Chuanjia Liu <chuanjia.liu@mediatek.com>
Date:   Mon Aug 23 11:27:58 2021 +0800

    PCI: mediatek: Use PCI domain to handle ports detection

    Use of_get_pci_domain_nr() to get the pci domain.

    If the "linux,pci-domain" property is present, we assume that the PCIe
    bridge is an individual bridge, hence we only need to parse one port.

    Link: https://lore.kernel.org/r/20210823032800.1660-5-chuanjia.liu@mediatek.com
    Signed-off-by: Chuanjia Liu <chuanjia.liu@mediatek.com>
    [lorenzo.pieralisi@arm.com: commit log]
    Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
    Acked-by: Ryder Lee <ryder.lee@mediatek.com>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-03-03 20:43:39 -07:00
Myron Stowe 805f24bac9 PCI: mediatek: Add new method to get irq number
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2045254
Upstream Status: 436960bb0045854119a61efab20578f55b311a87

commit 436960bb0045854119a61efab20578f55b311a87
Author: Chuanjia Liu <chuanjia.liu@mediatek.com>
Date:   Mon Aug 23 11:27:57 2021 +0800

    PCI: mediatek: Add new method to get irq number

    Use platform_get_irq_byname() to get the irq number
    if the "interrupt-names" property is defined.

    Link: https://lore.kernel.org/r/20210823032800.1660-4-chuanjia.liu@mediatek.com
    Signed-off-by: Chuanjia Liu <chuanjia.liu@mediatek.com>
    [lorenzo.pieralisi@arm.com: commit log]
    Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
    Acked-by: Ryder Lee <ryder.lee@mediatek.com>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-03-03 20:43:39 -07:00
Myron Stowe c085472c79 PCI: mediatek: Add new method to get shared pcie-cfg base address
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2045254
Upstream Status: 87e8657ba99cac87b84c7f8ead91b44d88345504

commit 87e8657ba99cac87b84c7f8ead91b44d88345504
Author: Chuanjia Liu <chuanjia.liu@mediatek.com>
Date:   Mon Aug 23 11:27:56 2021 +0800

    PCI: mediatek: Add new method to get shared pcie-cfg base address

    For the new dts format, add a new method to get
    shared pcie-cfg base address and use it to configure
    the PCIECFG controller

    Link: https://lore.kernel.org/r/20210823032800.1660-3-chuanjia.liu@mediatek.com
    Signed-off-by: Chuanjia Liu <chuanjia.liu@mediatek.com>
    Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
    Acked-by: Ryder Lee <ryder.lee@mediatek.com>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-03-03 20:43:38 -07:00
Myron Stowe cc06255630 PCI: Bulk conversion to generic_handle_domain_irq()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2045254
Upstream Status: d21faba11693c10072ce3b96b696445175f49be2

commit d21faba11693c10072ce3b96b696445175f49be2
Author: Marc Zyngier <maz@kernel.org>
Date:   Mon Aug 2 17:26:19 2021 +0100

    PCI: Bulk conversion to generic_handle_domain_irq()

    Wherever possible, replace constructs that match either
    generic_handle_irq(irq_find_mapping()) or
    generic_handle_irq(irq_linear_revmap()) to a single call to
    generic_handle_domain_irq().

    Link: https://lore.kernel.org/r/20210802162630.2219813-4-maz@kernel.org
    Signed-off-by: Marc Zyngier <maz@kernel.org>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2022-03-03 20:43:32 -07:00
Zhen Lei 28bba1e220 PCI: mediatek: Remove redundant error printing in mtk_pcie_subsys_powerup()
When devm_ioremap_resource() fails, a clear enough error message will be
printed by its subfunction __devm_ioremap_resource(). The error
information contains the device name, failure cause, and possibly resource
information.

Therefore, remove the error printing here to simplify code and reduce the
binary size.

Link: https://lore.kernel.org/r/20210511122453.6052-1-thunder.leizhen@huawei.com
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Krzysztof Wilczyński <kw@linux.com>
2021-06-03 17:45:52 +01:00
Bjorn Helgaas 51bc2b7ffd Merge branch 'remotes/lorenzo/pci/msi'
- Convert tegra to MSI domains (Marc Zyngier)

- Use rcar controller address as MSI doorbell instead of allocating a page
  (Marc Zyngier)

- Convert rcar to MSI domains (Marc Zyngier)

- Use xilinx port structure as MSI doorbell instead of allocating a page
  (Marc Zyngier)

- Convert xilinx to MSI domains (Marc Zyngier)

- Remove unused Hyper-V msi_controller structure (Marc Zyngier)

- Remove unused PCI core msi_controller support (Marc Zyngier)

- Remove struct msi_controller (Marc Zyngier)

- Remove unused default_teardown_msi_irqs() (Marc Zyngier)

- Let host bridges declare their reliance on MSI domains (Marc Zyngier)

- Make pci_host_common_probe() declare its reliance on MSI domains (Marc
  Zyngier)

- Advertise mediatek lack of built-in MSI handling (Thomas Gleixner)

- Document ways of ending up with NO_MSI (Marc Zyngier)

- Refactor HT advertising of NO_MSI flag (Marc Zyngier)

* remotes/lorenzo/pci/msi:
  PCI: Refactor HT advertising of NO_MSI flag
  PCI/MSI: Document the various ways of ending up with NO_MSI
  PCI: mediatek: Advertise lack of built-in MSI handling
  PCI/MSI: Make pci_host_common_probe() declare its reliance on MSI domains
  PCI/MSI: Let PCI host bridges declare their reliance on MSI domains
  PCI/MSI: Kill default_teardown_msi_irqs()
  PCI/MSI: Kill msi_controller structure
  PCI/MSI: Drop use of msi_controller from core code
  PCI: hv: Drop msi_controller structure
  PCI: xilinx: Convert to MSI domains
  PCI: xilinx: Don't allocate extra memory for the MSI capture address
  PCI: rcar: Convert to MSI domains
  PCI: rcar: Don't allocate extra memory for the MSI capture address
  PCI: tegra: Convert to MSI domains
2021-05-04 10:43:30 -05:00
Thomas Gleixner 645e9c3838 PCI: mediatek: Advertise lack of built-in MSI handling
Some Mediatek host bridges cannot handle MSIs, which is sad.
This also results in an ugly warning at device probe time,
as the core PCI code wasn't told that MSIs were not available.

Advertise this fact to the rest of the core PCI code by
using the 'msi_domain' attribute, which still opens the possibility
for another block to provide the MSI functionnality.

[maz: commit message, switched over to msi_domain attribute]

Link: https://lore.kernel.org/r/20210330151145.997953-13-maz@kernel.org
Reported-by: Frank Wunderlich <frank-w@public-files.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
2021-04-20 14:11:22 +01:00
Qiheng Lin 87db343f80 PCI: mediatek: Add missing MODULE_DEVICE_TABLE
This patch adds missing MODULE_DEVICE_TABLE definition which generates
correct modalias for automatic loading of this driver when it is built
as an external module.

Link: https://lore.kernel.org/r/20210331085938.3115-1-linqiheng@huawei.com
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qiheng Lin <linqiheng@huawei.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2021-04-13 11:47:34 +01:00
Ryder Lee 31ec9c2746 PCI: mediatek: Configure FC and FTS for functions other than 0
"PCI_FUNC(port->slot << 3)" is always 0, so previously
mtk_pcie_startup_port() only configured FC credits and FTs for function
0.

Compute "func" correctly so we also configure functions other than
0. This affects MT2701 and MT7623.

Link: https://lore.kernel.org/r/c529dbfc066f4bda9b87edbdbf771f207e69b84e.1604510053.git.ryder.lee@mediatek.com
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Krzysztof Wilczyński <kw@linux.com>
2021-03-29 16:01:31 +01:00
Krzysztof Wilczyński 42814c438a PCI: mediatek: Add missing of_node_put() to fix reference leak
The for_each_available_child_of_node helper internally makes use of the
of_get_next_available_child() which performs an of_node_get() on each
iteration when searching for next available child node.

Should an available child node be found, then it would return a device
node pointer with reference count incremented, thus early return from
the middle of the loop requires an explicit of_node_put() to prevent
reference count leak.

To stop the reference leak, explicitly call of_node_put() before
returning after an error occurred.

Link: https://lore.kernel.org/r/20210120184810.3068794-1-kw@linux.com
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2021-01-25 17:33:28 +00:00
Rob Herring b64aa11eb2 PCI: Set bridge map_irq and swizzle_irq to default functions
The majority of DT based host drivers use the default .map_irq() and
.swizzle_irq() functions, so let's initialize the function pointers to
the default and drop setting them in the host drivers.

Drivers like iProc which don't support legacy interrupts need to set
.map_irq() back to NULL.

Link: https://lore.kernel.org/r/20200722022514.1283916-20-robh@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
2020-08-04 16:36:30 +01:00
Rob Herring 669cbc7081 PCI: Move DT resource setup into devm_pci_alloc_host_bridge()
Now that pci_parse_request_of_pci_ranges() callers just setup
pci_host_bridge.windows and dma_ranges directly and don't need the bus
range returned, we can just initialize them when allocating the
pci_host_bridge struct.

With this, pci_parse_request_of_pci_ranges() becomes a static function.

Link: https://lore.kernel.org/r/20200722022514.1283916-19-robh@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
2020-08-04 16:36:30 +01:00
Rob Herring 4f5c883d78 PCI: Move setting pci_host_bridge.busnr out of host drivers
Most host drivers only parse the DT bus range to set the root bus number
in pci_host_bridge.busnr. The ones that don't set busnr are buggy in
that they ignore what's in DT. Let's set busnr in pci_scan_root_bus_bridge()
where we already check for the bus resource and remove setting it in
host drivers.

Link: https://lore.kernel.org/r/20200722022514.1283916-12-robh@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Jingoo Han <jingoohan1@gmail.com>
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Will Deacon <will@kernel.org>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: linux-tegra@vger.kernel.org
Cc: linux-mediatek@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
2020-07-23 17:13:06 +01:00
Rob Herring 6a589900d0 PCI: Set default bridge parent device
The host bridge's parent device is always the platform device. As we
already have a pointer to it in the devres functions, let's initialize
the parent device. Drivers can still override the parent if desired.

Link: https://lore.kernel.org/r/20200722022514.1283916-3-robh@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
2020-07-23 11:20:49 +01:00
Dejin Zheng e2dcd20b16 PCI: controller: Convert to devm_platform_ioremap_resource_byname()
Use devm_platform_ioremap_resource_byname() to simplify the code,
since it calls respectively platform_get_resource_byname() and
devm_ioremap_resource().

Link: https://lore.kernel.org/r/20200602171601.17630-1-zhengdejin5@gmail.com
Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
2020-07-10 11:50:23 +01:00
Aman Sharma 0584bff096 PCI: Check for platform_get_irq() failure consistently
The platform_get_irq*() interfaces return either a negative error number or
a valid IRQ.  0 is not a valid return value, so check for "< 0" to detect
failure as recommended by the function documentation.

On failure, return the error number from platform_get_irq*() instead of
making up a new one.

Link: https://lore.kernel.org/r/cover.1583952275.git.amanharitsh123@gmail.com
[bhelgaas: commit log, squash into one patch]
Signed-off-by: Aman Sharma <amanharitsh123@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Richard Zhu <hongxing.zhu@nxp.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Marc Gonzalez <marc.w.gonzalez@free.fr>
2020-05-12 08:14:43 -05:00
Rob Herring 331f634571 PCI: of: Add inbound resource parsing to helpers
Extend devm_of_pci_get_host_bridge_resources() and
pci_parse_request_of_pci_ranges() helpers to also parse the inbound
addresses from DT 'dma-ranges' and populate a resource list with the
translated addresses. This will help ensure 'dma-ranges' is always
parsed in a consistent way.

Tested-by: Srinath Mannam <srinath.mannam@broadcom.com>
Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Srinath Mannam <srinath.mannam@broadcom.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Jingoo Han <jingoohan1@gmail.com>
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Will Deacon <will@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Toan Le <toan@os.amperecomputing.com>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Tom Joseph <tjoseph@cadence.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Cc: Simon Horman <horms@verge.net.au>
Cc: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: rfi@lists.rocketboards.org
Cc: linux-mediatek@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
2019-11-20 16:59:58 +00:00
Rob Herring 8a26f861b8 PCI: mediatek: Use pci_parse_request_of_pci_ranges()
Convert Mediatek host bridge to use the common
pci_parse_request_of_pci_ranges().

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: linux-mediatek@lists.infradead.org
2019-10-29 10:49:47 +00:00
Bjorn Helgaas c5048a73b4 Merge branch 'pci/trivial'
- Fix typos and whitespace errors (Bjorn Helgaas, Krzysztof Wilczynski)

  - Remove unnecessary "return" statements (Krzysztof Wilczynski)

  - Correct of_irq_parse_pci() function documentation (Lubomir Rintel)

* pci/trivial:
  PCI: Remove unnecessary returns
  PCI: OF: Correct of_irq_parse_pci() documentation
  PCI: Fix typos and whitespace errors
2019-09-23 16:10:31 -05:00
Krzysztof Wilczynski 55507aea58 PCI: Remove unnecessary returns
Remove unnecessary "return" statements at the end of void functions.  No
functional change intended.

Link: https://lore.kernel.org/r/20190825221039.6977-1-kw@linux.com
Link: https://lore.kernel.org/r/20190826095143.21353-1-kw@linux.com
Signed-off-by: Krzysztof Wilczynski <kw@linux.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2019-08-30 14:00:34 -05:00
Jianjun Wang 0cccd42e61 PCI: mediatek: Add controller support for MT7629
MT7629 is an ARM platform SoC which has the same PCIe IP as MT7622.

The HW default value of its PCI host controller Device ID is invalid,
fix it to match the hardware implementation.

Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com>
[lorenzo.pieralisi@arm.com: commit log/minor spelling update]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2019-08-07 11:34:01 +01:00
Bjorn Helgaas ee6df38da8 Merge branch 'remotes/lorenzo/pci/misc'
- Exit pcitest with error code when test fails (Jean-Jacques Hiblot)

  - Fix leaked of_node references in dra7xx, uniphier, layerscape,
    rockchip, aardvark, iproc, mediatek, rpadlpar (Wen Yang)

  - Fix pcitest "help" option parsing (Kishon Vijay Abraham I)

  - Fix Makefile bug that inadvertently removes pcitest.sh (Kishon Vijay
    Abraham I)

  - Check for alloc_workqueue() failure in endpoint test driver (Kangjie
    Lu)

* remotes/lorenzo/pci/misc:
  PCI: endpoint: Fix a potential NULL pointer dereference
  tools: PCI: Handle pcitest.sh independently from pcitest
  tools: PCI: Add 'h' in optstring of getopt()
  PCI: mediatek: Fix a leaked reference by adding missing of_node_put()
  PCI: iproc: Fix a leaked reference by adding missing of_node_put()
  PCI: aardvark: Fix a leaked reference by adding missing of_node_put()
  PCI: rockchip: Fix a leaked reference by adding missing of_node_put()
  PCI: dwc: layerscape: Fix a leaked reference by adding missing of_node_put()
  PCI: uniphier: Fix a leaked reference by adding missing of_node_put()
  PCI: dwc: pci-dra7xx: Fix a leaked reference by adding missing of_node_put()
  tools: PCI: Exit with error code when test fails
2019-05-13 18:34:44 -05:00
Chunfeng Yun 6be22343cc PCI: mediatek: Get optional clocks with devm_clk_get_optional()
Update the driver to use devm_clk_get_optional() to claim
optional clocks instead of devm_clk_get().

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
Acked-by: Honghui Zhang <honghui.zhang@mediatek.com>
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Honghui Zhang <honghui.zhang@mediatek.com>
2019-04-11 09:56:01 +01:00
Wen Yang ff7a5a0a85 PCI: mediatek: Fix a leaked reference by adding missing of_node_put()
The call to of_get_next_child() returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

irq_domain_add_linear() also calls of_node_get() to increase refcount,
so irq_domain will not be affected when it is released.

Detected by coccinelle with the following warnings:
  ./drivers/pci/controller/pcie-mediatek.c:577:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 567, but without a corresponding object release within this function.
  ./drivers/pci/controller/pcie-mediatek.c:583:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 567, but without a corresponding object release within this function.
  ./drivers/pci/controller/pcie-mediatek.c:586:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 567, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Honghui Zhang <honghui.zhang@mediatek.com>
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: linux-pci@vger.kernel.org
Cc: linux-mediatek@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
2019-04-01 10:42:58 +01:00
Honghui Zhang cbe3a7728c PCI: mediatek: Enlarge PCIe2AHB window size to support 4GB DRAM
The PCIE_AXI_WINDOW0 register defines the inbound window size for
requests coming from PCI endpoints. Requests outside of this window will
be treated as unsupported requests.

Enlarge this window size from 2^31 to 2^33 to support a 8GB address
space (which gives endpoints DMA access to full 4GB DRAM address range
- physical DRAM starts at 0x40000000).

Reported-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: updated commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2019-03-01 11:22:21 +00:00
Honghui Zhang c61df57343 PCI: mediatek: Fix memory mapped IO range size computation
Mediatek's HW assigns a MMIO address range (typically starts from
0x20000000 to 0x2fffffff for both mt2712 and mt7622) for PCI usage.

This MMIO address space represents the address space that can
be allocated to PCI devices through Base Address Registers.

Even though the full MMIO address range is available to be allocated, it
should be enabled by the PCIE_AHB_TRANS_BASE register in the host
controller and the size that is enabled is determined by AHB2PCIE_SIZE
bits in this register.

Owing to a bug in the MMIO window size computation, current code does
not enable the full size of the available MMIO address range in the
PCI host controller; if the PCI devices BARs requested size exceeds the
size enabled through the PCIE_AHB_TRANS_BASE register the requests
targeting the disabled address address space will be blocked by the root
complex causing a system error.

Existing code has never run into a system error in production because
even half of the enabled MMIO range (128MB) is big enough for typical
devices BAR requests (4MB) but the full MMIO address range should
be enabled regardless.

Fix the MMIO window size computation by using resource_size(mem) instead
of mem->end - mem->start.

Since the MMIO window size for both MT2712 and MT7622 is 0x10000000,
this change will update the parameter passed to fls() from 0xfffffff to
0x10000000 and calculate the whole memory mapped IO range size
correctly.

Detected through coccinelle semantic patch (and related warning):

scripts/coccinelle/api/resource_size.cocci:

pcie-mediatek.c:720:13-16: WARNING: Suspicious code. resource_size is maybe missing with mem

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: rewrote the commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2019-03-01 11:16:46 +00:00
Honghui Zhang 7b96dc91be PCI: mediatek: Remove un-used variant in struct mtk_pcie_port
The "lane" variant in struct mtk_pcie_port is not used, remove it.

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2018-12-18 13:48:07 +00:00
Honghui Zhang 0c0f2f93e7 PCI: mediatek: Use devm_of_pci_get_host_bridge_resources() to parse DT
Use the devm_of_pci_get_host_bridge_resources() API in place of the PCI OF
DT parser.

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2018-11-30 10:25:59 +00:00
Honghui Zhang 031337ace2 PCI: mediatek: Add loadable kernel module support
Implement remove() callback function for the Mediatek PCIe controller
driver to add loadable kernel module support.

Save the PCIe's GIC IRQ at probe so that it can be retrieved to
call dispose_irq() to tear down the IRQ upon module removal.

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: updated commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Ryder Lee <ryder.lee@mediatek.com>
2018-10-17 15:37:29 +01:00
Honghui Zhang 97d2932fee PCI: mediatek: Add system PM support for MT2712 and MT7622
In order to reduce the PCIe power consumption in system suspend,
the PCI bus physical layer should be gated. On system resume, the PCIe
link should be re-established and the related control register values
should be restored.

Define suspend_noirq & resume_noirq callback functions to implement
PM system syspend hooks for the PCI host controller.

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: updated commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2018-10-17 15:37:05 +01:00
Honghui Zhang 3828d60fd2 PCI: mediatek: Fixup MSI enablement logic by enabling MSI before clocks
Commit 43e6409db6 ("PCI: mediatek: Add MSI support for MT2712 and
MT7622") added MSI support but enabled MSI in the wrong place, at a step
in the probe sequence where clocks were not still enabled.

Fix this issue by calling mtk_pcie_enable_msi() in mtk_pcie_startup_port_v2()
since clocks are enabled when mtk_pcie_startup_port_v2() is called.

To avoid forward declaration of mtk_pcie_enable_msi(), move the
mtk_pcie_startup_port_v2() function definition in the file.

Fixes: 43e6409db6 ("PCI: mediatek: Add MSI support for MT2712 and MT7622")
Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: squashed commit and adapted log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2018-10-17 15:36:17 +01:00
Honghui Zhang 57cb3152b3 PCI: mediatek: Convert to use pci_host_probe()
Part of mtk_pcie_register_host() is an open-coded version of
pci_host_probe(). So instead of duplicating this code, use
pci_host_probe() directly and remove mtk_pcie_register_host().

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: commit log changes]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2018-10-17 15:36:01 +01:00
Honghui Zhang 88c0e230bb PCI: mediatek: Remove the redundant dev->pm_domain check
There is no need to check whether device have a PM domain attached before
calling the PM runtime methods. Remove it.

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: commit log changes]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2018-10-17 15:35:34 +01:00
Honghui Zhang a7f172ab6a PCI: mediatek: Fix class type for MT7622 to PCI_CLASS_BRIDGE_PCI
commit 101c92dc80 ("PCI: mediatek: Set up vendor ID and class
type for MT7622") erroneously set the class type for MT7622 to
PCI_CLASS_BRIDGE_HOST.

The PCIe controller of MT7622 integrates a Root Port that has type 1
configuration space header and related bridge windows.

The HW default value of this bridge's class type is invalid.

Fix its class type and set it to PCI_CLASS_BRIDGE_PCI to
match the hardware implementation.

Fixes: 101c92dc80 ("PCI: mediatek: Set up vendor ID and class type for MT7622")
Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: reworked the commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2018-10-15 15:10:30 +01:00
Honghui Zhang 074d6f3268 PCI: mediatek: Fix mtk_pcie_find_port() endpoint/port matching logic
The Mediatek's host controller has two slots, each with its own control
registers. The host driver needs to identify what slot is connected to
what port in order to access the device's configuration space.

Current code retrieving slot connected to a given endpoint device.

Assuming each slot is connected to one endpoint device as below:

                host bridge
  bus 0 --> __________|_______
           |                  |
           |                  |
         slot 0             slot 1
  bus 1 -->|        bus 2 --> |
           |                  |
         EP 0               EP 1

During PCI enumeration, system software will scan all the PCI devices on
every bus starting from devfn 0. Using PCI_SLOT(devfn) for matching an
endpoint to its slot is erroneous in that the devfn does not contain the
hierarchical bus numbering in it. In order to match an endpoint with its
slot (and related port), the PCI tree must be walked up to the root bus
(where the root ports are situated) and then the PCI_SLOT(devfn)
matching logic can be correctly applied for matching.

This patch fixes the mtk_pcie_find_port() slot matching logic by adding
appropriate PCI tree walking code to retrieve the slot/port a given
endpoint is connected to.

Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
[lorenzo.pieralisi@arm.com: rewrote the commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ryder Lee <ryder.lee@mediatek.com>
2018-10-15 14:47:54 +01:00
Gustavo A. R. Silva 17a0a1e5f6 PCI: mediatek: Fix unchecked return value
Check return value of devm_pci_remap_iospace().

Addresses-Coverity-ID: 1471965 ("Unchecked return value")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Honghui Zhang <honghui.zhang@mediatek.com>
2018-09-18 11:44:39 +01:00
Sergei Shtylyov 438477b9a0 PCI: mediatek: Fix I/O space page leak
When testing the R-Car PCIe driver on the Condor board, if the PCIe PHY
driver was left disabled, the kernel crashed with this BUG:

  kernel BUG at lib/ioremap.c:72!
  Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
  Modules linked in:
  CPU: 0 PID: 39 Comm: kworker/0:1 Not tainted 4.17.0-dirty #1092
  Hardware name: Renesas Condor board based on r8a77980 (DT)
  Workqueue: events deferred_probe_work_func
  pstate: 80000005 (Nzcv daif -PAN -UAO)
  pc : ioremap_page_range+0x370/0x3c8
  lr : ioremap_page_range+0x40/0x3c8
  sp : ffff000008da39e0
  x29: ffff000008da39e0 x28: 00e8000000000f07
  x27: ffff7dfffee00000 x26: 0140000000000000
  x25: ffff7dfffef00000 x24: 00000000000fe100
  x23: ffff80007b906000 x22: ffff000008ab8000
  x21: ffff000008bb1d58 x20: ffff7dfffef00000
  x19: ffff800009c30fb8 x18: 0000000000000001
  x17: 00000000000152d0 x16: 00000000014012d0
  x15: 0000000000000000 x14: 0720072007200720
  x13: 0720072007200720 x12: 0720072007200720
  x11: 0720072007300730 x10: 00000000000000ae
  x9 : 0000000000000000 x8 : ffff7dffff000000
  x7 : 0000000000000000 x6 : 0000000000000100
  x5 : 0000000000000000 x4 : 000000007b906000
  x3 : ffff80007c61a880 x2 : ffff7dfffeefffff
  x1 : 0000000040000000 x0 : 00e80000fe100f07
  Process kworker/0:1 (pid: 39, stack limit = 0x        (ptrval))
  Call trace:
   ioremap_page_range+0x370/0x3c8
   pci_remap_iospace+0x7c/0xac
   pci_parse_request_of_pci_ranges+0x13c/0x190
   rcar_pcie_probe+0x4c/0xb04
   platform_drv_probe+0x50/0xbc
   driver_probe_device+0x21c/0x308
   __device_attach_driver+0x98/0xc8
   bus_for_each_drv+0x54/0x94
   __device_attach+0xc4/0x12c
   device_initial_probe+0x10/0x18
   bus_probe_device+0x90/0x98
   deferred_probe_work_func+0xb0/0x150
   process_one_work+0x12c/0x29c
   worker_thread+0x200/0x3fc
   kthread+0x108/0x134
   ret_from_fork+0x10/0x18
  Code: f9004ba2 54000080 aa0003fb 17ffff48 (d4210000)

It turned out that pci_remap_iospace() wasn't undone when the driver's
probe failed, and since devm_phy_optional_get() returned -EPROBE_DEFER,
the probe was retried, finally causing the BUG due to trying to remap
already remapped pages.

The MediaTek PCIe driver has the same issue.

Replace devm_pci_remap_iospace() with its devm_ managed counterpart
to fix the bug.

Fixes: 637cfacae9 ("PCI: mediatek: Add MediaTek PCIe host controller support")
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
[lorenzo.pieralisi@arm.com: updated the commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2018-07-18 17:01:36 -05:00
Shawn Lin 6e0832fa43 PCI: Collect all native drivers under drivers/pci/controller/
Native PCI drivers for root complex devices were originally all in
drivers/pci/host/.  Some of these devices can also be operated in endpoint
mode.  Drivers for endpoint mode didn't seem to fit in the "host"
directory, so we put both the root complex and endpoint drivers in
per-device directories, e.g., drivers/pci/dwc/, drivers/pci/cadence/, etc.

These per-device directories contain trivial Kconfig and Makefiles and
clutter drivers/pci/.  Make a new drivers/pci/controllers/ directory and
collect all the device-specific drivers there.

No functional change intended.

Link: https://lkml.kernel.org/r/1520304202-232891-1-git-send-email-shawn.lin@rock-chips.com
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2018-06-08 07:50:11 -05:00