mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 02:21:39 -04:00
PCI: dw-rockchip: Implement .reset_root_port() and use for link down
The PCIe link may go down in cases like firmware crashes or unstable connections. When this occurs, the Root Port must be reset to restore the functionality. However, the current driver lacks link down handling, forcing users to reboot the system to recover. Implement the .reset_root_port() callback for link down handling for the Rockchip DWC PCIe host controller. The RC is reset, reconfigured, and link training initiated to recover from the link down event. This also by extension fixes issues with sysfs-initiated bus resets. Currently, the endpoint device is non-functional after a sysfs initiated bus reset (it may link up with downgraded link status). With the link down handling support, a sysfs initiated bus reset works as intended. Testing conducted on a ROCK5B board with an M.2 NVMe drive. Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> Signed-off-by: Niklas Cassel <cassel@kernel.org> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com> [bhelgaas: subject] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://patch.msgid.link/20260727172654.605988-4-cassel@kernel.org
This commit is contained in:
committed by
Bjorn Helgaas
parent
4d88cb82a6
commit
b376b3ff9c
@@ -374,6 +374,7 @@ config PCIE_ROCKCHIP_DW_HOST
|
||||
depends on OF
|
||||
select PCIE_DW_HOST
|
||||
select PCIE_ROCKCHIP_DW
|
||||
select PCI_HOST_COMMON
|
||||
help
|
||||
Enables support for the DesignWare PCIe controller in the
|
||||
Rockchip SoC (except RK3399) to work in host mode.
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <trace/events/pci_controller.h>
|
||||
|
||||
#include "../../pci.h"
|
||||
#include "../pci-host-common.h"
|
||||
#include "pcie-designware.h"
|
||||
|
||||
/*
|
||||
@@ -122,6 +123,9 @@ struct rockchip_pcie_of_data {
|
||||
const struct pci_epc_features *epc_features;
|
||||
};
|
||||
|
||||
static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge,
|
||||
struct pci_dev *pdev);
|
||||
|
||||
static int rockchip_pcie_readl_apb(struct rockchip_pcie *rockchip, u32 reg)
|
||||
{
|
||||
return readl_relaxed(rockchip->apb_base + reg);
|
||||
@@ -436,6 +440,7 @@ static int rockchip_pcie_host_init(struct dw_pcie_rp *pp)
|
||||
|
||||
rockchip_pcie_configure_l1ss(pci);
|
||||
rockchip_pcie_enable_l0s(pci);
|
||||
pp->bridge->reset_root_port = rockchip_pcie_rc_reset_root_port;
|
||||
|
||||
/* Disable Root Ports BAR0 and BAR1 as they report bogus size */
|
||||
dw_pcie_writel_dbi2(pci, PCI_BASE_ADDRESS_0, 0x0);
|
||||
@@ -634,6 +639,32 @@ static const struct dw_pcie_ops dw_pcie_ops = {
|
||||
.get_ltssm = rockchip_pcie_get_ltssm,
|
||||
};
|
||||
|
||||
static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
|
||||
{
|
||||
struct rockchip_pcie *rockchip = arg;
|
||||
struct dw_pcie *pci = &rockchip->pci;
|
||||
struct dw_pcie_rp *pp = &pci->pp;
|
||||
struct device *dev = pci->dev;
|
||||
struct pci_dev *port;
|
||||
u32 reg;
|
||||
|
||||
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
|
||||
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
|
||||
|
||||
dev_dbg(dev, "PCIE_CLIENT_INTR_STATUS_MISC: %#x\n", reg);
|
||||
dev_dbg(dev, "LTSSM_STATUS: %#x\n", rockchip_pcie_get_ltssm_reg(rockchip));
|
||||
|
||||
if (reg & PCIE_LINK_REQ_RST_NOT_INT) {
|
||||
dev_dbg(dev, "hot reset or link-down reset\n");
|
||||
for_each_pci_bridge(port, pp->bridge->bus) {
|
||||
if (pci_pcie_type(port) == PCI_EXP_TYPE_ROOT_PORT)
|
||||
pci_host_handle_link_down(port);
|
||||
}
|
||||
}
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
|
||||
{
|
||||
struct rockchip_pcie *rockchip = arg;
|
||||
@@ -666,14 +697,29 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int rockchip_pcie_configure_rc(struct rockchip_pcie *rockchip)
|
||||
static int rockchip_pcie_configure_rc(struct platform_device *pdev,
|
||||
struct rockchip_pcie *rockchip)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct dw_pcie_rp *pp;
|
||||
int irq, ret;
|
||||
u32 val;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_PCIE_ROCKCHIP_DW_HOST))
|
||||
return -ENODEV;
|
||||
|
||||
irq = platform_get_irq_byname(pdev, "sys");
|
||||
if (irq < 0)
|
||||
return irq;
|
||||
|
||||
ret = devm_request_threaded_irq(dev, irq, NULL,
|
||||
rockchip_pcie_rc_sys_irq_thread,
|
||||
IRQF_ONESHOT, "pcie-sys-rc", rockchip);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to request PCIe sys IRQ\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* LTSSM enable control mode */
|
||||
val = FIELD_PREP_WM16(PCIE_LTSSM_ENABLE_ENHANCE, 1);
|
||||
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
|
||||
@@ -685,7 +731,17 @@ static int rockchip_pcie_configure_rc(struct rockchip_pcie *rockchip)
|
||||
pp = &rockchip->pci.pp;
|
||||
pp->ops = &rockchip_pcie_host_ops;
|
||||
|
||||
return dw_pcie_host_init(pp);
|
||||
ret = dw_pcie_host_init(pp);
|
||||
if (ret) {
|
||||
dev_err(dev, "failed to initialize host\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* unmask hot reset/link-down reset */
|
||||
val = FIELD_PREP_WM16(PCIE_LINK_REQ_RST_NOT_INT, 0);
|
||||
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_INTR_MASK_MISC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rockchip_pcie_configure_ep(struct platform_device *pdev,
|
||||
@@ -804,7 +860,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
|
||||
|
||||
switch (data->mode) {
|
||||
case DW_PCIE_RC_TYPE:
|
||||
ret = rockchip_pcie_configure_rc(rockchip);
|
||||
ret = rockchip_pcie_configure_rc(pdev, rockchip);
|
||||
if (ret)
|
||||
goto deinit_clk;
|
||||
break;
|
||||
@@ -829,6 +885,78 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge,
|
||||
struct pci_dev *pdev)
|
||||
{
|
||||
struct pci_bus *bus = bridge->bus;
|
||||
struct dw_pcie_rp *pp = bus->sysdata;
|
||||
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
||||
struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
|
||||
struct device *dev = rockchip->pci.dev;
|
||||
u32 val;
|
||||
int ret;
|
||||
|
||||
dw_pcie_stop_link(pci);
|
||||
clk_bulk_disable_unprepare(rockchip->clk_cnt, rockchip->clks);
|
||||
rockchip_pcie_phy_deinit(rockchip);
|
||||
|
||||
ret = reset_control_assert(rockchip->rst);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = rockchip_pcie_phy_init(rockchip);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = reset_control_deassert(rockchip->rst);
|
||||
if (ret)
|
||||
goto deinit_phy;
|
||||
|
||||
ret = rockchip_pcie_clk_init(rockchip);
|
||||
if (ret)
|
||||
goto deinit_phy;
|
||||
|
||||
ret = pp->ops->init(pp);
|
||||
if (ret) {
|
||||
dev_err(dev, "Host init failed: %d\n", ret);
|
||||
goto deinit_clk;
|
||||
}
|
||||
|
||||
/* LTSSM enable control mode */
|
||||
val = FIELD_PREP_WM16(PCIE_LTSSM_ENABLE_ENHANCE, 1);
|
||||
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
|
||||
|
||||
rockchip_pcie_writel_apb(rockchip,
|
||||
PCIE_CLIENT_SET_MODE(PCIE_CLIENT_MODE_RC),
|
||||
PCIE_CLIENT_GENERAL_CON);
|
||||
|
||||
ret = dw_pcie_setup_rc(pp);
|
||||
if (ret) {
|
||||
dev_err(dev, "Failed to setup RC: %d\n", ret);
|
||||
goto deinit_clk;
|
||||
}
|
||||
|
||||
/* unmask hot reset/link-down reset */
|
||||
val = FIELD_PREP_WM16(PCIE_LINK_REQ_RST_NOT_INT, 0);
|
||||
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_INTR_MASK_MISC);
|
||||
|
||||
ret = dw_pcie_start_link(pci);
|
||||
if (ret)
|
||||
goto deinit_clk;
|
||||
|
||||
/* Ignore errors, the link may come up later */
|
||||
dw_pcie_wait_for_link(pci);
|
||||
dev_dbg(dev, "Root Port reset completed\n");
|
||||
return ret;
|
||||
|
||||
deinit_clk:
|
||||
clk_bulk_disable_unprepare(rockchip->clk_cnt, rockchip->clks);
|
||||
deinit_phy:
|
||||
rockchip_pcie_phy_deinit(rockchip);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct rockchip_pcie_of_data rockchip_pcie_rc_of_data_rk3568 = {
|
||||
.mode = DW_PCIE_RC_TYPE,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user