]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI: dwc: ep: Add dw_pcie_ep_hide_ext_capability()
authorNiklas Cassel <cassel@kernel.org>
Mon, 10 Mar 2025 09:48:27 +0000 (10:48 +0100)
committerKrzysztof Wilczyński <kwilczynski@kernel.org>
Fri, 14 Mar 2025 16:13:19 +0000 (16:13 +0000)
Add dw_pcie_ep_hide_ext_capability() which can be used by an endpoint
controller driver to hide a capability.

This can be useful to hide a capability that is buggy, such that the
host side does not try to enable the buggy capability.

Suggested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Link: https://lore.kernel.org/r/20250310094826.842681-5-cassel@kernel.org
drivers/pci/controller/dwc/pcie-designware-ep.c
drivers/pci/controller/dwc/pcie-designware.h

index 2212609632c4e4aed1e49621d7764f39c1fbc5da..5a6174e107c20c897cfa142687e219c5ecafb8c6 100644 (file)
@@ -102,6 +102,45 @@ static u8 dw_pcie_ep_find_capability(struct dw_pcie_ep *ep, u8 func_no, u8 cap)
        return __dw_pcie_ep_find_next_cap(ep, func_no, next_cap_ptr, cap);
 }
 
+/**
+ * dw_pcie_ep_hide_ext_capability - Hide a capability from the linked list
+ * @pci: DWC PCI device
+ * @prev_cap: Capability preceding the capability that should be hidden
+ * @cap: Capability that should be hidden
+ *
+ * Return: 0 if success, errno otherwise.
+ */
+int dw_pcie_ep_hide_ext_capability(struct dw_pcie *pci, u8 prev_cap, u8 cap)
+{
+       u16 prev_cap_offset, cap_offset;
+       u32 prev_cap_header, cap_header;
+
+       prev_cap_offset = dw_pcie_find_ext_capability(pci, prev_cap);
+       if (!prev_cap_offset)
+               return -EINVAL;
+
+       prev_cap_header = dw_pcie_readl_dbi(pci, prev_cap_offset);
+       cap_offset = PCI_EXT_CAP_NEXT(prev_cap_header);
+       cap_header = dw_pcie_readl_dbi(pci, cap_offset);
+
+       /* cap must immediately follow prev_cap. */
+       if (PCI_EXT_CAP_ID(cap_header) != cap)
+               return -EINVAL;
+
+       /* Clear next ptr. */
+       prev_cap_header &= ~GENMASK(31, 20);
+
+       /* Set next ptr to next ptr of cap. */
+       prev_cap_header |= cap_header & GENMASK(31, 20);
+
+       dw_pcie_dbi_ro_wr_en(pci);
+       dw_pcie_writel_dbi(pci, prev_cap_offset, prev_cap_header);
+       dw_pcie_dbi_ro_wr_dis(pci);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(dw_pcie_ep_hide_ext_capability);
+
 static int dw_pcie_ep_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
                                   struct pci_epf_header *hdr)
 {
index a03b3799fb2766d60ce444c423cb1b8f445c8b42..2d1de81d47b67fc0df941484b1d92d986b2b4dbd 100644 (file)
@@ -781,6 +781,7 @@ int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8 func_no,
                                       u16 interrupt_num);
 void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar);
+int dw_pcie_ep_hide_ext_capability(struct dw_pcie *pci, u8 prev_cap, u8 cap);
 struct dw_pcie_ep_func *
 dw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no);
 #else
@@ -838,6 +839,12 @@ static inline void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
 {
 }
 
+static inline int dw_pcie_ep_hide_ext_capability(struct dw_pcie *pci,
+                                                u8 prev_cap, u8 cap)
+{
+       return 0;
+}
+
 static inline struct dw_pcie_ep_func *
 dw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no)
 {