Skip to content

Commit 318ed91

Browse files
committed
Merge branch 'remotes/lorenzo/pci/aardvark'
- Use LTSSM state to build link training flag since Aardvark doesn't implement the Link Training bit (Remi Pommarel) - Delay before training Aardvark link in case PERST# was asserted before the driver probe (Remi Pommarel) - Fix Aardvark issues with Root Control reads and writes (Remi Pommarel) - Don't rely on jiffies in Aardvark config access path since interrupts may be disabled (Remi Pommarel) - Fix Aardvark big-endian support (Grzegorz Jaszczyk) - Fix bridge emulation big-endian support (Grzegorz Jaszczyk) * remotes/lorenzo/pci/aardvark: PCI: pci-bridge-emul: Fix big-endian support PCI: aardvark: Fix big endian support PCI: aardvark: Don't rely on jiffies while holding spinlock PCI: aardvark: Fix PCI_EXP_RTCTL register configuration PCI: aardvark: Wait for endpoint to be ready before training link PCI: aardvark: Use LTSSM state to build link training flag
2 parents f52412b + e0d9d30 commit 318ed91

File tree

3 files changed

+109
-66
lines changed

3 files changed

+109
-66
lines changed

drivers/pci/controller/pci-aardvark.c

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,14 @@
176176
(PCIE_CONF_BUS(bus) | PCIE_CONF_DEV(PCI_SLOT(devfn)) | \
177177
PCIE_CONF_FUNC(PCI_FUNC(devfn)) | PCIE_CONF_REG(where))
178178

179-
#define PIO_TIMEOUT_MS 1
179+
#define PIO_RETRY_CNT 500
180+
#define PIO_RETRY_DELAY 2 /* 2 us*/
180181

181182
#define LINK_WAIT_MAX_RETRIES 10
182183
#define LINK_WAIT_USLEEP_MIN 90000
183184
#define LINK_WAIT_USLEEP_MAX 100000
185+
#define RETRAIN_WAIT_MAX_RETRIES 10
186+
#define RETRAIN_WAIT_USLEEP_US 2000
184187

185188
#define MSI_IRQ_NUM 32
186189

@@ -240,6 +243,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)
240243
return -ETIMEDOUT;
241244
}
242245

246+
static void advk_pcie_wait_for_retrain(struct advk_pcie *pcie)
247+
{
248+
size_t retries;
249+
250+
for (retries = 0; retries < RETRAIN_WAIT_MAX_RETRIES; ++retries) {
251+
if (!advk_pcie_link_up(pcie))
252+
break;
253+
udelay(RETRAIN_WAIT_USLEEP_US);
254+
}
255+
}
256+
243257
static void advk_pcie_setup_hw(struct advk_pcie *pcie)
244258
{
245259
u32 reg;
@@ -325,6 +339,14 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
325339
reg |= PIO_CTRL_ADDR_WIN_DISABLE;
326340
advk_writel(pcie, reg, PIO_CTRL);
327341

342+
/*
343+
* PERST# signal could have been asserted by pinctrl subsystem before
344+
* probe() callback has been called, making the endpoint going into
345+
* fundamental reset. As required by PCI Express spec a delay for at
346+
* least 100ms after such a reset before link training is needed.
347+
*/
348+
msleep(PCI_PM_D3COLD_WAIT);
349+
328350
/* Start link training */
329351
reg = advk_readl(pcie, PCIE_CORE_LINK_CTRL_STAT_REG);
330352
reg |= PCIE_CORE_LINK_TRAINING;
@@ -384,17 +406,16 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie)
384406
static int advk_pcie_wait_pio(struct advk_pcie *pcie)
385407
{
386408
struct device *dev = &pcie->pdev->dev;
387-
unsigned long timeout;
409+
int i;
388410

389-
timeout = jiffies + msecs_to_jiffies(PIO_TIMEOUT_MS);
390-
391-
while (time_before(jiffies, timeout)) {
411+
for (i = 0; i < PIO_RETRY_CNT; i++) {
392412
u32 start, isr;
393413

394414
start = advk_readl(pcie, PIO_START);
395415
isr = advk_readl(pcie, PIO_ISR);
396416
if (!start && isr)
397417
return 0;
418+
udelay(PIO_RETRY_DELAY);
398419
}
399420

400421
dev_err(dev, "config read/write timed out\n");
@@ -416,7 +437,7 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
416437

417438
case PCI_EXP_RTCTL: {
418439
u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG);
419-
*value = (val & PCIE_MSG_PM_PME_MASK) ? PCI_EXP_RTCTL_PMEIE : 0;
440+
*value = (val & PCIE_MSG_PM_PME_MASK) ? 0 : PCI_EXP_RTCTL_PMEIE;
420441
return PCI_BRIDGE_EMUL_HANDLED;
421442
}
422443

@@ -427,11 +448,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
427448
return PCI_BRIDGE_EMUL_HANDLED;
428449
}
429450

451+
case PCI_EXP_LNKCTL: {
452+
/* u32 contains both PCI_EXP_LNKCTL and PCI_EXP_LNKSTA */
453+
u32 val = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg) &
454+
~(PCI_EXP_LNKSTA_LT << 16);
455+
if (!advk_pcie_link_up(pcie))
456+
val |= (PCI_EXP_LNKSTA_LT << 16);
457+
*value = val;
458+
return PCI_BRIDGE_EMUL_HANDLED;
459+
}
460+
430461
case PCI_CAP_LIST_ID:
431462
case PCI_EXP_DEVCAP:
432463
case PCI_EXP_DEVCTL:
433464
case PCI_EXP_LNKCAP:
434-
case PCI_EXP_LNKCTL:
435465
*value = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg);
436466
return PCI_BRIDGE_EMUL_HANDLED;
437467
default:
@@ -448,14 +478,24 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
448478

449479
switch (reg) {
450480
case PCI_EXP_DEVCTL:
481+
advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg);
482+
break;
483+
451484
case PCI_EXP_LNKCTL:
452485
advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg);
486+
if (new & PCI_EXP_LNKCTL_RL)
487+
advk_pcie_wait_for_retrain(pcie);
453488
break;
454489

455-
case PCI_EXP_RTCTL:
456-
new = (new & PCI_EXP_RTCTL_PMEIE) << 3;
457-
advk_writel(pcie, new, PCIE_ISR0_MASK_REG);
490+
case PCI_EXP_RTCTL: {
491+
/* Only mask/unmask PME interrupt */
492+
u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG) &
493+
~PCIE_MSG_PM_PME_MASK;
494+
if ((new & PCI_EXP_RTCTL_PMEIE) == 0)
495+
val |= PCIE_MSG_PM_PME_MASK;
496+
advk_writel(pcie, val, PCIE_ISR0_MASK_REG);
458497
break;
498+
}
459499

460500
case PCI_EXP_RTSTA:
461501
new = (new & PCI_EXP_RTSTA_PME) >> 9;
@@ -480,18 +520,20 @@ static void advk_sw_pci_bridge_init(struct advk_pcie *pcie)
480520
{
481521
struct pci_bridge_emul *bridge = &pcie->bridge;
482522

483-
bridge->conf.vendor = advk_readl(pcie, PCIE_CORE_DEV_ID_REG) & 0xffff;
484-
bridge->conf.device = advk_readl(pcie, PCIE_CORE_DEV_ID_REG) >> 16;
523+
bridge->conf.vendor =
524+
cpu_to_le16(advk_readl(pcie, PCIE_CORE_DEV_ID_REG) & 0xffff);
525+
bridge->conf.device =
526+
cpu_to_le16(advk_readl(pcie, PCIE_CORE_DEV_ID_REG) >> 16);
485527
bridge->conf.class_revision =
486-
advk_readl(pcie, PCIE_CORE_DEV_REV_REG) & 0xff;
528+
cpu_to_le32(advk_readl(pcie, PCIE_CORE_DEV_REV_REG) & 0xff);
487529

488530
/* Support 32 bits I/O addressing */
489531
bridge->conf.iobase = PCI_IO_RANGE_TYPE_32;
490532
bridge->conf.iolimit = PCI_IO_RANGE_TYPE_32;
491533

492534
/* Support 64 bits memory pref */
493-
bridge->conf.pref_mem_base = PCI_PREF_RANGE_TYPE_64;
494-
bridge->conf.pref_mem_limit = PCI_PREF_RANGE_TYPE_64;
535+
bridge->conf.pref_mem_base = cpu_to_le16(PCI_PREF_RANGE_TYPE_64);
536+
bridge->conf.pref_mem_limit = cpu_to_le16(PCI_PREF_RANGE_TYPE_64);
495537

496538
/* Support interrupt A for MSI feature */
497539
bridge->conf.intpin = PCIE_CORE_INT_A_ASSERT_ENABLE;

drivers/pci/pci-bridge-emul.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ static const struct pci_bridge_reg_behavior pcie_cap_regs_behavior[] = {
270270
int pci_bridge_emul_init(struct pci_bridge_emul *bridge,
271271
unsigned int flags)
272272
{
273-
bridge->conf.class_revision |= PCI_CLASS_BRIDGE_PCI << 16;
273+
bridge->conf.class_revision |= cpu_to_le32(PCI_CLASS_BRIDGE_PCI << 16);
274274
bridge->conf.header_type = PCI_HEADER_TYPE_BRIDGE;
275275
bridge->conf.cache_line_size = 0x10;
276-
bridge->conf.status = PCI_STATUS_CAP_LIST;
276+
bridge->conf.status = cpu_to_le16(PCI_STATUS_CAP_LIST);
277277
bridge->pci_regs_behavior = kmemdup(pci_regs_behavior,
278278
sizeof(pci_regs_behavior),
279279
GFP_KERNEL);
@@ -284,8 +284,9 @@ int pci_bridge_emul_init(struct pci_bridge_emul *bridge,
284284
bridge->conf.capabilities_pointer = PCI_CAP_PCIE_START;
285285
bridge->pcie_conf.cap_id = PCI_CAP_ID_EXP;
286286
/* Set PCIe v2, root port, slot support */
287-
bridge->pcie_conf.cap = PCI_EXP_TYPE_ROOT_PORT << 4 | 2 |
288-
PCI_EXP_FLAGS_SLOT;
287+
bridge->pcie_conf.cap =
288+
cpu_to_le16(PCI_EXP_TYPE_ROOT_PORT << 4 | 2 |
289+
PCI_EXP_FLAGS_SLOT);
289290
bridge->pcie_cap_regs_behavior =
290291
kmemdup(pcie_cap_regs_behavior,
291292
sizeof(pcie_cap_regs_behavior),
@@ -327,7 +328,7 @@ int pci_bridge_emul_conf_read(struct pci_bridge_emul *bridge, int where,
327328
int reg = where & ~3;
328329
pci_bridge_emul_read_status_t (*read_op)(struct pci_bridge_emul *bridge,
329330
int reg, u32 *value);
330-
u32 *cfgspace;
331+
__le32 *cfgspace;
331332
const struct pci_bridge_reg_behavior *behavior;
332333

333334
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_END) {
@@ -343,11 +344,11 @@ int pci_bridge_emul_conf_read(struct pci_bridge_emul *bridge, int where,
343344
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_START) {
344345
reg -= PCI_CAP_PCIE_START;
345346
read_op = bridge->ops->read_pcie;
346-
cfgspace = (u32 *) &bridge->pcie_conf;
347+
cfgspace = (__le32 *) &bridge->pcie_conf;
347348
behavior = bridge->pcie_cap_regs_behavior;
348349
} else {
349350
read_op = bridge->ops->read_base;
350-
cfgspace = (u32 *) &bridge->conf;
351+
cfgspace = (__le32 *) &bridge->conf;
351352
behavior = bridge->pci_regs_behavior;
352353
}
353354

@@ -357,7 +358,7 @@ int pci_bridge_emul_conf_read(struct pci_bridge_emul *bridge, int where,
357358
ret = PCI_BRIDGE_EMUL_NOT_HANDLED;
358359

359360
if (ret == PCI_BRIDGE_EMUL_NOT_HANDLED)
360-
*value = cfgspace[reg / 4];
361+
*value = le32_to_cpu(cfgspace[reg / 4]);
361362

362363
/*
363364
* Make sure we never return any reserved bit with a value
@@ -387,7 +388,7 @@ int pci_bridge_emul_conf_write(struct pci_bridge_emul *bridge, int where,
387388
int mask, ret, old, new, shift;
388389
void (*write_op)(struct pci_bridge_emul *bridge, int reg,
389390
u32 old, u32 new, u32 mask);
390-
u32 *cfgspace;
391+
__le32 *cfgspace;
391392
const struct pci_bridge_reg_behavior *behavior;
392393

393394
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_END)
@@ -414,11 +415,11 @@ int pci_bridge_emul_conf_write(struct pci_bridge_emul *bridge, int where,
414415
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_START) {
415416
reg -= PCI_CAP_PCIE_START;
416417
write_op = bridge->ops->write_pcie;
417-
cfgspace = (u32 *) &bridge->pcie_conf;
418+
cfgspace = (__le32 *) &bridge->pcie_conf;
418419
behavior = bridge->pcie_cap_regs_behavior;
419420
} else {
420421
write_op = bridge->ops->write_base;
421-
cfgspace = (u32 *) &bridge->conf;
422+
cfgspace = (__le32 *) &bridge->conf;
422423
behavior = bridge->pci_regs_behavior;
423424
}
424425

@@ -431,7 +432,7 @@ int pci_bridge_emul_conf_write(struct pci_bridge_emul *bridge, int where,
431432
/* Clear the W1C bits */
432433
new &= ~((value << shift) & (behavior[reg / 4].w1c & mask));
433434

434-
cfgspace[reg / 4] = new;
435+
cfgspace[reg / 4] = cpu_to_le32(new);
435436

436437
if (write_op)
437438
write_op(bridge, reg, old, new, mask);

drivers/pci/pci-bridge-emul.h

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,65 @@
66

77
/* PCI configuration space of a PCI-to-PCI bridge. */
88
struct pci_bridge_emul_conf {
9-
u16 vendor;
10-
u16 device;
11-
u16 command;
12-
u16 status;
13-
u32 class_revision;
9+
__le16 vendor;
10+
__le16 device;
11+
__le16 command;
12+
__le16 status;
13+
__le32 class_revision;
1414
u8 cache_line_size;
1515
u8 latency_timer;
1616
u8 header_type;
1717
u8 bist;
18-
u32 bar[2];
18+
__le32 bar[2];
1919
u8 primary_bus;
2020
u8 secondary_bus;
2121
u8 subordinate_bus;
2222
u8 secondary_latency_timer;
2323
u8 iobase;
2424
u8 iolimit;
25-
u16 secondary_status;
26-
u16 membase;
27-
u16 memlimit;
28-
u16 pref_mem_base;
29-
u16 pref_mem_limit;
30-
u32 prefbaseupper;
31-
u32 preflimitupper;
32-
u16 iobaseupper;
33-
u16 iolimitupper;
25+
__le16 secondary_status;
26+
__le16 membase;
27+
__le16 memlimit;
28+
__le16 pref_mem_base;
29+
__le16 pref_mem_limit;
30+
__le32 prefbaseupper;
31+
__le32 preflimitupper;
32+
__le16 iobaseupper;
33+
__le16 iolimitupper;
3434
u8 capabilities_pointer;
3535
u8 reserve[3];
36-
u32 romaddr;
36+
__le32 romaddr;
3737
u8 intline;
3838
u8 intpin;
39-
u16 bridgectrl;
39+
__le16 bridgectrl;
4040
};
4141

4242
/* PCI configuration space of the PCIe capabilities */
4343
struct pci_bridge_emul_pcie_conf {
4444
u8 cap_id;
4545
u8 next;
46-
u16 cap;
47-
u32 devcap;
48-
u16 devctl;
49-
u16 devsta;
50-
u32 lnkcap;
51-
u16 lnkctl;
52-
u16 lnksta;
53-
u32 slotcap;
54-
u16 slotctl;
55-
u16 slotsta;
56-
u16 rootctl;
57-
u16 rsvd;
58-
u32 rootsta;
59-
u32 devcap2;
60-
u16 devctl2;
61-
u16 devsta2;
62-
u32 lnkcap2;
63-
u16 lnkctl2;
64-
u16 lnksta2;
65-
u32 slotcap2;
66-
u16 slotctl2;
67-
u16 slotsta2;
46+
__le16 cap;
47+
__le32 devcap;
48+
__le16 devctl;
49+
__le16 devsta;
50+
__le32 lnkcap;
51+
__le16 lnkctl;
52+
__le16 lnksta;
53+
__le32 slotcap;
54+
__le16 slotctl;
55+
__le16 slotsta;
56+
__le16 rootctl;
57+
__le16 rsvd;
58+
__le32 rootsta;
59+
__le32 devcap2;
60+
__le16 devctl2;
61+
__le16 devsta2;
62+
__le32 lnkcap2;
63+
__le16 lnkctl2;
64+
__le16 lnksta2;
65+
__le32 slotcap2;
66+
__le16 slotctl2;
67+
__le16 slotsta2;
6868
};
6969

7070
struct pci_bridge_emul;

0 commit comments

Comments
 (0)