Skip to content

Commit e3d6957

Browse files
floatiouskwilczynski
authored andcommitted
PCI: dwc: ep: Add dw_pcie_ep_hide_ext_capability()
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 <[email protected]> Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8189aa5 commit e3d6957

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

drivers/pci/controller/dwc/pcie-designware-ep.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,45 @@ static u8 dw_pcie_ep_find_capability(struct dw_pcie_ep *ep, u8 func_no, u8 cap)
102102
return __dw_pcie_ep_find_next_cap(ep, func_no, next_cap_ptr, cap);
103103
}
104104

105+
/**
106+
* dw_pcie_ep_hide_ext_capability - Hide a capability from the linked list
107+
* @pci: DWC PCI device
108+
* @prev_cap: Capability preceding the capability that should be hidden
109+
* @cap: Capability that should be hidden
110+
*
111+
* Return: 0 if success, errno otherwise.
112+
*/
113+
int dw_pcie_ep_hide_ext_capability(struct dw_pcie *pci, u8 prev_cap, u8 cap)
114+
{
115+
u16 prev_cap_offset, cap_offset;
116+
u32 prev_cap_header, cap_header;
117+
118+
prev_cap_offset = dw_pcie_find_ext_capability(pci, prev_cap);
119+
if (!prev_cap_offset)
120+
return -EINVAL;
121+
122+
prev_cap_header = dw_pcie_readl_dbi(pci, prev_cap_offset);
123+
cap_offset = PCI_EXT_CAP_NEXT(prev_cap_header);
124+
cap_header = dw_pcie_readl_dbi(pci, cap_offset);
125+
126+
/* cap must immediately follow prev_cap. */
127+
if (PCI_EXT_CAP_ID(cap_header) != cap)
128+
return -EINVAL;
129+
130+
/* Clear next ptr. */
131+
prev_cap_header &= ~GENMASK(31, 20);
132+
133+
/* Set next ptr to next ptr of cap. */
134+
prev_cap_header |= cap_header & GENMASK(31, 20);
135+
136+
dw_pcie_dbi_ro_wr_en(pci);
137+
dw_pcie_writel_dbi(pci, prev_cap_offset, prev_cap_header);
138+
dw_pcie_dbi_ro_wr_dis(pci);
139+
140+
return 0;
141+
}
142+
EXPORT_SYMBOL_GPL(dw_pcie_ep_hide_ext_capability);
143+
105144
static int dw_pcie_ep_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
106145
struct pci_epf_header *hdr)
107146
{

drivers/pci/controller/dwc/pcie-designware.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
781781
int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8 func_no,
782782
u16 interrupt_num);
783783
void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar);
784+
int dw_pcie_ep_hide_ext_capability(struct dw_pcie *pci, u8 prev_cap, u8 cap);
784785
struct dw_pcie_ep_func *
785786
dw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no);
786787
#else
@@ -838,6 +839,12 @@ static inline void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
838839
{
839840
}
840841

842+
static inline int dw_pcie_ep_hide_ext_capability(struct dw_pcie *pci,
843+
u8 prev_cap, u8 cap)
844+
{
845+
return 0;
846+
}
847+
841848
static inline struct dw_pcie_ep_func *
842849
dw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no)
843850
{

0 commit comments

Comments
 (0)