Skip to content

Commit 7873b49

Browse files
shimodaykwilczynski
authored andcommitted
PCI: dwc: endpoint: Add multiple PFs support for dbi2
The commit 24ede43 ("PCI: designware-ep: Add multiple PFs support for DWC") added .func_conf_select() to get the configuration space of different PFs and assumed that the offsets between dbi and dbi2 would be the same. However, Renesas R-Car Gen4 PCIe controllers have different offsets of function 1: dbi (+0x1000) and dbi2 (+0x800). To get the offset for dbi2, add .get_dbi2_offset() and dw_pcie_ep_get_dbi2_offset(). Note: - .func_conf_select() should be renamed later. - dw_pcie_ep_get_dbi2_offset() will call .func_conf_select() if .get_dbi2_offset() doesn't exist for backward compatibility. - dw_pcie_writeX_{dbi/dbi2} APIs accepted the func_no argument, so that these offset calculations are contained in the API definitions itself as it should. Link: https://lore.kernel.org/linux-pci/20231018085631.1121289-6-yoshihiro.shimoda.uh@renesas.com Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
1 parent 1a97454 commit 7873b49

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,35 @@ static unsigned int dw_pcie_ep_func_select(struct dw_pcie_ep *ep, u8 func_no)
5252
return func_offset;
5353
}
5454

55+
static unsigned int dw_pcie_ep_get_dbi2_offset(struct dw_pcie_ep *ep, u8 func_no)
56+
{
57+
unsigned int dbi2_offset = 0;
58+
59+
if (ep->ops->get_dbi2_offset)
60+
dbi2_offset = ep->ops->get_dbi2_offset(ep, func_no);
61+
else if (ep->ops->func_conf_select) /* for backward compatibility */
62+
dbi2_offset = ep->ops->func_conf_select(ep, func_no);
63+
64+
return dbi2_offset;
65+
}
66+
5567
static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, u8 func_no,
5668
enum pci_barno bar, int flags)
5769
{
58-
u32 reg;
59-
unsigned int func_offset = 0;
70+
unsigned int func_offset, dbi2_offset;
6071
struct dw_pcie_ep *ep = &pci->ep;
72+
u32 reg, reg_dbi2;
6173

6274
func_offset = dw_pcie_ep_func_select(ep, func_no);
75+
dbi2_offset = dw_pcie_ep_get_dbi2_offset(ep, func_no);
6376

6477
reg = func_offset + PCI_BASE_ADDRESS_0 + (4 * bar);
78+
reg_dbi2 = dbi2_offset + PCI_BASE_ADDRESS_0 + (4 * bar);
6579
dw_pcie_dbi_ro_wr_en(pci);
66-
dw_pcie_writel_dbi2(pci, reg, 0x0);
80+
dw_pcie_writel_dbi2(pci, reg_dbi2, 0x0);
6781
dw_pcie_writel_dbi(pci, reg, 0x0);
6882
if (flags & PCI_BASE_ADDRESS_MEM_TYPE_64) {
69-
dw_pcie_writel_dbi2(pci, reg + 4, 0x0);
83+
dw_pcie_writel_dbi2(pci, reg_dbi2 + 4, 0x0);
7084
dw_pcie_writel_dbi(pci, reg + 4, 0x0);
7185
}
7286
dw_pcie_dbi_ro_wr_dis(pci);
@@ -228,16 +242,18 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
228242
{
229243
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
230244
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
245+
unsigned int func_offset, dbi2_offset;
231246
enum pci_barno bar = epf_bar->barno;
232247
size_t size = epf_bar->size;
233248
int flags = epf_bar->flags;
234-
unsigned int func_offset = 0;
249+
u32 reg, reg_dbi2;
235250
int ret, type;
236-
u32 reg;
237251

238252
func_offset = dw_pcie_ep_func_select(ep, func_no);
253+
dbi2_offset = dw_pcie_ep_get_dbi2_offset(ep, func_no);
239254

240255
reg = PCI_BASE_ADDRESS_0 + (4 * bar) + func_offset;
256+
reg_dbi2 = PCI_BASE_ADDRESS_0 + (4 * bar) + dbi2_offset;
241257

242258
if (!(flags & PCI_BASE_ADDRESS_SPACE))
243259
type = PCIE_ATU_TYPE_MEM;
@@ -253,11 +269,11 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
253269

254270
dw_pcie_dbi_ro_wr_en(pci);
255271

256-
dw_pcie_writel_dbi2(pci, reg, lower_32_bits(size - 1));
272+
dw_pcie_writel_dbi2(pci, reg_dbi2, lower_32_bits(size - 1));
257273
dw_pcie_writel_dbi(pci, reg, flags);
258274

259275
if (flags & PCI_BASE_ADDRESS_MEM_TYPE_64) {
260-
dw_pcie_writel_dbi2(pci, reg + 4, upper_32_bits(size - 1));
276+
dw_pcie_writel_dbi2(pci, reg_dbi2 + 4, upper_32_bits(size - 1));
261277
dw_pcie_writel_dbi(pci, reg + 4, 0);
262278
}
263279

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ struct dw_pcie_ep_ops {
341341
* driver.
342342
*/
343343
unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8 func_no);
344+
unsigned int (*get_dbi2_offset)(struct dw_pcie_ep *ep, u8 func_no);
344345
};
345346

346347
struct dw_pcie_ep_func {

0 commit comments

Comments
 (0)