Skip to content

Commit 24ede43

Browse files
Xiaowei BaoLorenzo Pieralisi
authored andcommitted
PCI: designware-ep: Add multiple PFs support for DWC
Add multiple PFs support for DWC, due to different PF have different config space, we use func_conf_select callback function to access the different PF's config space, the different chip company need to implement this callback function when use the DWC IP core and intend to support multiple PFs feature. Link: https://lore.kernel.org/r/20200918080024.13639-2-Zhiqiang.Hou@nxp.com Signed-off-by: Xiaowei Bao <xiaowei.bao@nxp.com> Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Reviewed-by: Rob Herring <robh@kernel.org> Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
1 parent fdd056f commit 24ede43

3 files changed

Lines changed: 143 additions & 59 deletions

File tree

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

Lines changed: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,26 @@ void dw_pcie_ep_init_notify(struct dw_pcie_ep *ep)
3030
}
3131
EXPORT_SYMBOL_GPL(dw_pcie_ep_init_notify);
3232

33-
static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar,
34-
int flags)
33+
static unsigned int dw_pcie_ep_func_select(struct dw_pcie_ep *ep, u8 func_no)
34+
{
35+
unsigned int func_offset = 0;
36+
37+
if (ep->ops->func_conf_select)
38+
func_offset = ep->ops->func_conf_select(ep, func_no);
39+
40+
return func_offset;
41+
}
42+
43+
static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, u8 func_no,
44+
enum pci_barno bar, int flags)
3545
{
3646
u32 reg;
47+
unsigned int func_offset = 0;
48+
struct dw_pcie_ep *ep = &pci->ep;
49+
50+
func_offset = dw_pcie_ep_func_select(ep, func_no);
3751

38-
reg = PCI_BASE_ADDRESS_0 + (4 * bar);
52+
reg = func_offset + PCI_BASE_ADDRESS_0 + (4 * bar);
3953
dw_pcie_dbi_ro_wr_en(pci);
4054
dw_pcie_writel_dbi2(pci, reg, 0x0);
4155
dw_pcie_writel_dbi(pci, reg, 0x0);
@@ -48,36 +62,44 @@ static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar,
4862

4963
void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
5064
{
51-
__dw_pcie_ep_reset_bar(pci, bar, 0);
65+
u8 func_no, funcs;
66+
67+
funcs = pci->ep.epc->max_functions;
68+
69+
for (func_no = 0; func_no < funcs; func_no++)
70+
__dw_pcie_ep_reset_bar(pci, func_no, bar, 0);
5271
}
5372

5473
static int dw_pcie_ep_write_header(struct pci_epc *epc, u8 func_no,
5574
struct pci_epf_header *hdr)
5675
{
5776
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
5877
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
78+
unsigned int func_offset = 0;
79+
80+
func_offset = dw_pcie_ep_func_select(ep, func_no);
5981

6082
dw_pcie_dbi_ro_wr_en(pci);
61-
dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, hdr->vendorid);
62-
dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, hdr->deviceid);
63-
dw_pcie_writeb_dbi(pci, PCI_REVISION_ID, hdr->revid);
64-
dw_pcie_writeb_dbi(pci, PCI_CLASS_PROG, hdr->progif_code);
65-
dw_pcie_writew_dbi(pci, PCI_CLASS_DEVICE,
83+
dw_pcie_writew_dbi(pci, func_offset + PCI_VENDOR_ID, hdr->vendorid);
84+
dw_pcie_writew_dbi(pci, func_offset + PCI_DEVICE_ID, hdr->deviceid);
85+
dw_pcie_writeb_dbi(pci, func_offset + PCI_REVISION_ID, hdr->revid);
86+
dw_pcie_writeb_dbi(pci, func_offset + PCI_CLASS_PROG, hdr->progif_code);
87+
dw_pcie_writew_dbi(pci, func_offset + PCI_CLASS_DEVICE,
6688
hdr->subclass_code | hdr->baseclass_code << 8);
67-
dw_pcie_writeb_dbi(pci, PCI_CACHE_LINE_SIZE,
89+
dw_pcie_writeb_dbi(pci, func_offset + PCI_CACHE_LINE_SIZE,
6890
hdr->cache_line_size);
69-
dw_pcie_writew_dbi(pci, PCI_SUBSYSTEM_VENDOR_ID,
91+
dw_pcie_writew_dbi(pci, func_offset + PCI_SUBSYSTEM_VENDOR_ID,
7092
hdr->subsys_vendor_id);
71-
dw_pcie_writew_dbi(pci, PCI_SUBSYSTEM_ID, hdr->subsys_id);
72-
dw_pcie_writeb_dbi(pci, PCI_INTERRUPT_PIN,
93+
dw_pcie_writew_dbi(pci, func_offset + PCI_SUBSYSTEM_ID, hdr->subsys_id);
94+
dw_pcie_writeb_dbi(pci, func_offset + PCI_INTERRUPT_PIN,
7395
hdr->interrupt_pin);
7496
dw_pcie_dbi_ro_wr_dis(pci);
7597

7698
return 0;
7799
}
78100

79-
static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, enum pci_barno bar,
80-
dma_addr_t cpu_addr,
101+
static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no,
102+
enum pci_barno bar, dma_addr_t cpu_addr,
81103
enum dw_pcie_as_type as_type)
82104
{
83105
int ret;
@@ -90,7 +112,7 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, enum pci_barno bar,
90112
return -EINVAL;
91113
}
92114

93-
ret = dw_pcie_prog_inbound_atu(pci, free_win, bar, cpu_addr,
115+
ret = dw_pcie_prog_inbound_atu(pci, func_no, free_win, bar, cpu_addr,
94116
as_type);
95117
if (ret < 0) {
96118
dev_err(pci->dev, "Failed to program IB window\n");
@@ -103,7 +125,8 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, enum pci_barno bar,
103125
return 0;
104126
}
105127

106-
static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, phys_addr_t phys_addr,
128+
static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, u8 func_no,
129+
phys_addr_t phys_addr,
107130
u64 pci_addr, size_t size)
108131
{
109132
u32 free_win;
@@ -115,8 +138,8 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, phys_addr_t phys_addr,
115138
return -EINVAL;
116139
}
117140

118-
dw_pcie_prog_outbound_atu(pci, free_win, PCIE_ATU_TYPE_MEM,
119-
phys_addr, pci_addr, size);
141+
dw_pcie_prog_ep_outbound_atu(pci, func_no, free_win, PCIE_ATU_TYPE_MEM,
142+
phys_addr, pci_addr, size);
120143

121144
set_bit(free_win, ep->ob_window_map);
122145
ep->outbound_addr[free_win] = phys_addr;
@@ -132,7 +155,7 @@ static void dw_pcie_ep_clear_bar(struct pci_epc *epc, u8 func_no,
132155
enum pci_barno bar = epf_bar->barno;
133156
u32 atu_index = ep->bar_to_atu[bar];
134157

135-
__dw_pcie_ep_reset_bar(pci, bar, epf_bar->flags);
158+
__dw_pcie_ep_reset_bar(pci, func_no, bar, epf_bar->flags);
136159

137160
dw_pcie_disable_atu(pci, atu_index, DW_PCIE_REGION_INBOUND);
138161
clear_bit(atu_index, ep->ib_window_map);
@@ -149,14 +172,20 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no,
149172
size_t size = epf_bar->size;
150173
int flags = epf_bar->flags;
151174
enum dw_pcie_as_type as_type;
152-
u32 reg = PCI_BASE_ADDRESS_0 + (4 * bar);
175+
u32 reg;
176+
unsigned int func_offset = 0;
177+
178+
func_offset = dw_pcie_ep_func_select(ep, func_no);
179+
180+
reg = PCI_BASE_ADDRESS_0 + (4 * bar) + func_offset;
153181

154182
if (!(flags & PCI_BASE_ADDRESS_SPACE))
155183
as_type = DW_PCIE_AS_MEM;
156184
else
157185
as_type = DW_PCIE_AS_IO;
158186

159-
ret = dw_pcie_ep_inbound_atu(ep, bar, epf_bar->phys_addr, as_type);
187+
ret = dw_pcie_ep_inbound_atu(ep, func_no, bar,
188+
epf_bar->phys_addr, as_type);
160189
if (ret)
161190
return ret;
162191

@@ -215,7 +244,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no,
215244
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
216245
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
217246

218-
ret = dw_pcie_ep_outbound_atu(ep, addr, pci_addr, size);
247+
ret = dw_pcie_ep_outbound_atu(ep, func_no, addr, pci_addr, size);
219248
if (ret) {
220249
dev_err(pci->dev, "Failed to enable address\n");
221250
return ret;
@@ -229,11 +258,14 @@ static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no)
229258
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
230259
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
231260
u32 val, reg;
261+
unsigned int func_offset = 0;
232262

233263
if (!ep->msi_cap)
234264
return -EINVAL;
235265

236-
reg = ep->msi_cap + PCI_MSI_FLAGS;
266+
func_offset = dw_pcie_ep_func_select(ep, func_no);
267+
268+
reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
237269
val = dw_pcie_readw_dbi(pci, reg);
238270
if (!(val & PCI_MSI_FLAGS_ENABLE))
239271
return -EINVAL;
@@ -248,11 +280,14 @@ static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts)
248280
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
249281
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
250282
u32 val, reg;
283+
unsigned int func_offset = 0;
251284

252285
if (!ep->msi_cap)
253286
return -EINVAL;
254287

255-
reg = ep->msi_cap + PCI_MSI_FLAGS;
288+
func_offset = dw_pcie_ep_func_select(ep, func_no);
289+
290+
reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
256291
val = dw_pcie_readw_dbi(pci, reg);
257292
val &= ~PCI_MSI_FLAGS_QMASK;
258293
val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK;
@@ -268,11 +303,14 @@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no)
268303
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
269304
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
270305
u32 val, reg;
306+
unsigned int func_offset = 0;
271307

272308
if (!ep->msix_cap)
273309
return -EINVAL;
274310

275-
reg = ep->msix_cap + PCI_MSIX_FLAGS;
311+
func_offset = dw_pcie_ep_func_select(ep, func_no);
312+
313+
reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
276314
val = dw_pcie_readw_dbi(pci, reg);
277315
if (!(val & PCI_MSIX_FLAGS_ENABLE))
278316
return -EINVAL;
@@ -288,23 +326,26 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts,
288326
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
289327
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
290328
u32 val, reg;
329+
unsigned int func_offset = 0;
291330

292331
if (!ep->msix_cap)
293332
return -EINVAL;
294333

295334
dw_pcie_dbi_ro_wr_en(pci);
296335

297-
reg = ep->msix_cap + PCI_MSIX_FLAGS;
336+
func_offset = dw_pcie_ep_func_select(ep, func_no);
337+
338+
reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
298339
val = dw_pcie_readw_dbi(pci, reg);
299340
val &= ~PCI_MSIX_FLAGS_QSIZE;
300341
val |= interrupts;
301342
dw_pcie_writew_dbi(pci, reg, val);
302343

303-
reg = ep->msix_cap + PCI_MSIX_TABLE;
344+
reg = ep->msix_cap + func_offset + PCI_MSIX_TABLE;
304345
val = offset | bir;
305346
dw_pcie_writel_dbi(pci, reg, val);
306347

307-
reg = ep->msix_cap + PCI_MSIX_PBA;
348+
reg = ep->msix_cap + func_offset + PCI_MSIX_PBA;
308349
val = (offset + (interrupts * PCI_MSIX_ENTRY_SIZE)) | bir;
309350
dw_pcie_writel_dbi(pci, reg, val);
310351

@@ -389,6 +430,7 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
389430
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
390431
struct pci_epc *epc = ep->epc;
391432
unsigned int aligned_offset;
433+
unsigned int func_offset = 0;
392434
u16 msg_ctrl, msg_data;
393435
u32 msg_addr_lower, msg_addr_upper, reg;
394436
u64 msg_addr;
@@ -398,20 +440,22 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
398440
if (!ep->msi_cap)
399441
return -EINVAL;
400442

443+
func_offset = dw_pcie_ep_func_select(ep, func_no);
444+
401445
/* Raise MSI per the PCI Local Bus Specification Revision 3.0, 6.8.1. */
402-
reg = ep->msi_cap + PCI_MSI_FLAGS;
446+
reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
403447
msg_ctrl = dw_pcie_readw_dbi(pci, reg);
404448
has_upper = !!(msg_ctrl & PCI_MSI_FLAGS_64BIT);
405-
reg = ep->msi_cap + PCI_MSI_ADDRESS_LO;
449+
reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_LO;
406450
msg_addr_lower = dw_pcie_readl_dbi(pci, reg);
407451
if (has_upper) {
408-
reg = ep->msi_cap + PCI_MSI_ADDRESS_HI;
452+
reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_HI;
409453
msg_addr_upper = dw_pcie_readl_dbi(pci, reg);
410-
reg = ep->msi_cap + PCI_MSI_DATA_64;
454+
reg = ep->msi_cap + func_offset + PCI_MSI_DATA_64;
411455
msg_data = dw_pcie_readw_dbi(pci, reg);
412456
} else {
413457
msg_addr_upper = 0;
414-
reg = ep->msi_cap + PCI_MSI_DATA_32;
458+
reg = ep->msi_cap + func_offset + PCI_MSI_DATA_32;
415459
msg_data = dw_pcie_readw_dbi(pci, reg);
416460
}
417461
aligned_offset = msg_addr_lower & (epc->mem->window.page_size - 1);
@@ -430,19 +474,22 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
430474
}
431475

432476
int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
433-
u16 interrupt_num)
477+
u16 interrupt_num)
434478
{
435479
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
436480
struct pci_epf_msix_tbl *msix_tbl;
437481
struct pci_epc *epc = ep->epc;
482+
unsigned int func_offset = 0;
438483
u32 reg, msg_data, vec_ctrl;
439484
unsigned int aligned_offset;
440485
u32 tbl_offset;
441486
u64 msg_addr;
442487
int ret;
443488
u8 bir;
444489

445-
reg = ep->msix_cap + PCI_MSIX_TABLE;
490+
func_offset = dw_pcie_ep_func_select(ep, func_no);
491+
492+
reg = ep->msix_cap + func_offset + PCI_MSIX_TABLE;
446493
tbl_offset = dw_pcie_readl_dbi(pci, reg);
447494
bir = (tbl_offset & PCI_MSIX_TABLE_BIR);
448495
tbl_offset &= PCI_MSIX_TABLE_OFFSET;
@@ -607,13 +654,13 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
607654
ep->epc = epc;
608655
epc_set_drvdata(epc, ep);
609656

610-
if (ep->ops->ep_init)
611-
ep->ops->ep_init(ep);
612-
613657
ret = of_property_read_u8(np, "max-functions", &epc->max_functions);
614658
if (ret < 0)
615659
epc->max_functions = 1;
616660

661+
if (ep->ops->ep_init)
662+
ep->ops->ep_init(ep);
663+
617664
ret = pci_epc_mem_init(epc, ep->phys_base, ep->addr_size,
618665
ep->page_size);
619666
if (ret < 0) {

0 commit comments

Comments
 (0)