Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: dwc: Add start_link/stop_link inlines

Factor out this pattern:

if (!pci->ops || !pci->ops->start_link)
return -EINVAL;

return pci->ops->start_link(pci);

into a new dw_pcie_start_link() wrapper and do the same for the stop_link()
method.

Note that dw_pcie_ep_start() previously returned -EINVAL if there was no
platform start_link() method, which didn't make much sense since that is
not an error. It will now return 0 in that case.

As a side-effect, drop the empty start_link() and dummy dw_pcie_ops
instances from the generic DW PCIe and Layerscape EP platform drivers.

[bhelgaas: commit log]
Link: https://lore.kernel.org/r/20220624143428.8334-14-Sergey.Semin@baikalelectronics.ru
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

authored by

Serge Semin and committed by
Bjorn Helgaas
a37beefb bd42f310

+20 -34
-12
drivers/pci/controller/dwc/pci-layerscape-ep.c
··· 32 32 const struct ls_pcie_ep_drvdata *drvdata; 33 33 }; 34 34 35 - static int ls_pcie_establish_link(struct dw_pcie *pci) 36 - { 37 - return 0; 38 - } 39 - 40 - static const struct dw_pcie_ops dw_ls_pcie_ep_ops = { 41 - .start_link = ls_pcie_establish_link, 42 - }; 43 - 44 35 static const struct pci_epc_features* 45 36 ls_pcie_ep_get_features(struct dw_pcie_ep *ep) 46 37 { ··· 97 106 98 107 static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = { 99 108 .ops = &ls_pcie_ep_ops, 100 - .dw_pcie_ops = &dw_ls_pcie_ep_ops, 101 109 }; 102 110 103 111 static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = { 104 112 .func_offset = 0x20000, 105 113 .ops = &ls_pcie_ep_ops, 106 - .dw_pcie_ops = &dw_ls_pcie_ep_ops, 107 114 }; 108 115 109 116 static const struct ls_pcie_ep_drvdata lx2_ep_drvdata = { 110 117 .func_offset = 0x8000, 111 118 .ops = &ls_pcie_ep_ops, 112 - .dw_pcie_ops = &dw_ls_pcie_ep_ops, 113 119 }; 114 120 115 121 static const struct of_device_id ls_pcie_ep_of_match[] = {
+2 -6
drivers/pci/controller/dwc/pcie-designware-ep.c
··· 435 435 struct dw_pcie_ep *ep = epc_get_drvdata(epc); 436 436 struct dw_pcie *pci = to_dw_pcie_from_ep(ep); 437 437 438 - if (pci->ops && pci->ops->stop_link) 439 - pci->ops->stop_link(pci); 438 + dw_pcie_stop_link(pci); 440 439 } 441 440 442 441 static int dw_pcie_ep_start(struct pci_epc *epc) ··· 443 444 struct dw_pcie_ep *ep = epc_get_drvdata(epc); 444 445 struct dw_pcie *pci = to_dw_pcie_from_ep(ep); 445 446 446 - if (!pci->ops || !pci->ops->start_link) 447 - return -EINVAL; 448 - 449 - return pci->ops->start_link(pci); 447 + return dw_pcie_start_link(pci); 450 448 } 451 449 452 450 static const struct pci_epc_features*
+4 -6
drivers/pci/controller/dwc/pcie-designware-host.c
··· 409 409 410 410 dw_pcie_setup_rc(pp); 411 411 412 - if (!dw_pcie_link_up(pci) && pci->ops && pci->ops->start_link) { 413 - ret = pci->ops->start_link(pci); 412 + if (!dw_pcie_link_up(pci)) { 413 + ret = dw_pcie_start_link(pci); 414 414 if (ret) 415 415 goto err_free_msi; 416 416 } ··· 427 427 return 0; 428 428 429 429 err_stop_link: 430 - if (pci->ops && pci->ops->stop_link) 431 - pci->ops->stop_link(pci); 430 + dw_pcie_stop_link(pci); 432 431 433 432 err_free_msi: 434 433 if (pp->has_msi_ctrl) ··· 443 444 pci_stop_root_bus(pp->bridge->bus); 444 445 pci_remove_root_bus(pp->bridge->bus); 445 446 446 - if (pci->ops && pci->ops->stop_link) 447 - pci->ops->stop_link(pci); 447 + dw_pcie_stop_link(pci); 448 448 449 449 if (pp->has_msi_ctrl) 450 450 dw_pcie_free_msi(pp);
-10
drivers/pci/controller/dwc/pcie-designware-plat.c
··· 36 36 static const struct dw_pcie_host_ops dw_plat_pcie_host_ops = { 37 37 }; 38 38 39 - static int dw_plat_pcie_establish_link(struct dw_pcie *pci) 40 - { 41 - return 0; 42 - } 43 - 44 - static const struct dw_pcie_ops dw_pcie_ops = { 45 - .start_link = dw_plat_pcie_establish_link, 46 - }; 47 - 48 39 static void dw_plat_pcie_ep_init(struct dw_pcie_ep *ep) 49 40 { 50 41 struct dw_pcie *pci = to_dw_pcie_from_ep(ep); ··· 131 140 return -ENOMEM; 132 141 133 142 pci->dev = dev; 134 - pci->ops = &dw_pcie_ops; 135 143 136 144 dw_plat_pcie->pci = pci; 137 145 dw_plat_pcie->mode = mode;
+14
drivers/pci/controller/dwc/pcie-designware.h
··· 365 365 dw_pcie_writel_dbi(pci, reg, val); 366 366 } 367 367 368 + static inline int dw_pcie_start_link(struct dw_pcie *pci) 369 + { 370 + if (pci->ops && pci->ops->start_link) 371 + return pci->ops->start_link(pci); 372 + 373 + return 0; 374 + } 375 + 376 + static inline void dw_pcie_stop_link(struct dw_pcie *pci) 377 + { 378 + if (pci->ops && pci->ops->stop_link) 379 + pci->ops->stop_link(pci); 380 + } 381 + 368 382 #ifdef CONFIG_PCIE_DW_HOST 369 383 irqreturn_t dw_handle_msi_irq(struct pcie_port *pp); 370 384 void dw_pcie_setup_rc(struct pcie_port *pp);