Skip to content

Commit fc9a7d3

Browse files
committed
Merge branch 'pci/enumeration'
- Allow 'isolated PCI functions' (multi-function devices without a function 0) for LoongArch, similar to s390 and jailhouse (Huacai Chen) - Mask out unrelated bits in PCIE_LNKCAP_SLS2SPEED() and PCIE_LNKCTL2_TLS2SPEED(), which makes them more robust and fixes a WARN_ON_ONCE() in pcie_set_target_speed() (Jiwei Sun) - Read Link Control 2 again when retraining a link after a training failure so we try to increase the link speed (Jiwei Sun) - Allow built-in drivers, not just modular drivers, to use async initial probing (Lukas Wunner) - Support Immediate Readiness even on devices with no PM Capability (Sean Christopherson) * pci/enumeration: PCI: Support Immediate Readiness on devices without PM capabilities PCI: Allow built-in drivers to use async initial probing PCI: Adjust the position of reading the Link Control 2 register PCI: Fix link speed calculation on retrain failure PCI: Extend isolated function probing to LoongArch
2 parents e6035a0 + 5c0d0ee commit fc9a7d3

6 files changed

Lines changed: 37 additions & 23 deletions

File tree

drivers/pci/bus.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ void pci_bus_add_device(struct pci_dev *dev)
341341
{
342342
struct device_node *dn = dev->dev.of_node;
343343
struct platform_device *pdev;
344-
int retval;
345344

346345
/*
347346
* Can not put in pci_device_add yet because resources
@@ -372,9 +371,7 @@ void pci_bus_add_device(struct pci_dev *dev)
372371
if (!dn || of_device_is_available(dn))
373372
pci_dev_allow_binding(dev);
374373

375-
retval = device_attach(&dev->dev);
376-
if (retval < 0 && retval != -EPROBE_DEFER)
377-
pci_warn(dev, "device attach failed (%d)\n", retval);
374+
device_initial_probe(&dev->dev);
378375

379376
pci_dev_assign_added(dev);
380377
}

drivers/pci/pci.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,7 +3205,6 @@ void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev)
32053205
void pci_pm_init(struct pci_dev *dev)
32063206
{
32073207
int pm;
3208-
u16 status;
32093208
u16 pmc;
32103209

32113210
device_enable_async_suspend(&dev->dev);
@@ -3266,9 +3265,6 @@ void pci_pm_init(struct pci_dev *dev)
32663265
pci_pme_active(dev, false);
32673266
}
32683267

3269-
pci_read_config_word(dev, PCI_STATUS, &status);
3270-
if (status & PCI_STATUS_IMM_READY)
3271-
dev->imm_ready = 1;
32723268
pci_pm_power_up_and_verify_state(dev);
32733269
pm_runtime_forbid(&dev->dev);
32743270
pm_runtime_set_active(&dev->dev);

drivers/pci/pci.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,14 @@ void pci_bus_put(struct pci_bus *bus);
391391

392392
#define PCIE_LNKCAP_SLS2SPEED(lnkcap) \
393393
({ \
394-
((lnkcap) == PCI_EXP_LNKCAP_SLS_64_0GB ? PCIE_SPEED_64_0GT : \
395-
(lnkcap) == PCI_EXP_LNKCAP_SLS_32_0GB ? PCIE_SPEED_32_0GT : \
396-
(lnkcap) == PCI_EXP_LNKCAP_SLS_16_0GB ? PCIE_SPEED_16_0GT : \
397-
(lnkcap) == PCI_EXP_LNKCAP_SLS_8_0GB ? PCIE_SPEED_8_0GT : \
398-
(lnkcap) == PCI_EXP_LNKCAP_SLS_5_0GB ? PCIE_SPEED_5_0GT : \
399-
(lnkcap) == PCI_EXP_LNKCAP_SLS_2_5GB ? PCIE_SPEED_2_5GT : \
394+
u32 lnkcap_sls = (lnkcap) & PCI_EXP_LNKCAP_SLS; \
395+
\
396+
(lnkcap_sls == PCI_EXP_LNKCAP_SLS_64_0GB ? PCIE_SPEED_64_0GT : \
397+
lnkcap_sls == PCI_EXP_LNKCAP_SLS_32_0GB ? PCIE_SPEED_32_0GT : \
398+
lnkcap_sls == PCI_EXP_LNKCAP_SLS_16_0GB ? PCIE_SPEED_16_0GT : \
399+
lnkcap_sls == PCI_EXP_LNKCAP_SLS_8_0GB ? PCIE_SPEED_8_0GT : \
400+
lnkcap_sls == PCI_EXP_LNKCAP_SLS_5_0GB ? PCIE_SPEED_5_0GT : \
401+
lnkcap_sls == PCI_EXP_LNKCAP_SLS_2_5GB ? PCIE_SPEED_2_5GT : \
400402
PCI_SPEED_UNKNOWN); \
401403
})
402404

@@ -411,13 +413,17 @@ void pci_bus_put(struct pci_bus *bus);
411413
PCI_SPEED_UNKNOWN)
412414

413415
#define PCIE_LNKCTL2_TLS2SPEED(lnkctl2) \
414-
((lnkctl2) == PCI_EXP_LNKCTL2_TLS_64_0GT ? PCIE_SPEED_64_0GT : \
415-
(lnkctl2) == PCI_EXP_LNKCTL2_TLS_32_0GT ? PCIE_SPEED_32_0GT : \
416-
(lnkctl2) == PCI_EXP_LNKCTL2_TLS_16_0GT ? PCIE_SPEED_16_0GT : \
417-
(lnkctl2) == PCI_EXP_LNKCTL2_TLS_8_0GT ? PCIE_SPEED_8_0GT : \
418-
(lnkctl2) == PCI_EXP_LNKCTL2_TLS_5_0GT ? PCIE_SPEED_5_0GT : \
419-
(lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \
420-
PCI_SPEED_UNKNOWN)
416+
({ \
417+
u16 lnkctl2_tls = (lnkctl2) & PCI_EXP_LNKCTL2_TLS; \
418+
\
419+
(lnkctl2_tls == PCI_EXP_LNKCTL2_TLS_64_0GT ? PCIE_SPEED_64_0GT : \
420+
lnkctl2_tls == PCI_EXP_LNKCTL2_TLS_32_0GT ? PCIE_SPEED_32_0GT : \
421+
lnkctl2_tls == PCI_EXP_LNKCTL2_TLS_16_0GT ? PCIE_SPEED_16_0GT : \
422+
lnkctl2_tls == PCI_EXP_LNKCTL2_TLS_8_0GT ? PCIE_SPEED_8_0GT : \
423+
lnkctl2_tls == PCI_EXP_LNKCTL2_TLS_5_0GT ? PCIE_SPEED_5_0GT : \
424+
lnkctl2_tls == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \
425+
PCI_SPEED_UNKNOWN); \
426+
})
421427

422428
/* PCIe speed to Mb/s reduced by encoding overhead */
423429
#define PCIE_SPEED2MBS_ENC(speed) \

drivers/pci/probe.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,15 @@ void pcie_report_downtraining(struct pci_dev *dev)
25952595
__pcie_print_link_status(dev, false);
25962596
}
25972597

2598+
static void pci_imm_ready_init(struct pci_dev *dev)
2599+
{
2600+
u16 status;
2601+
2602+
pci_read_config_word(dev, PCI_STATUS, &status);
2603+
if (status & PCI_STATUS_IMM_READY)
2604+
dev->imm_ready = 1;
2605+
}
2606+
25982607
static void pci_init_capabilities(struct pci_dev *dev)
25992608
{
26002609
pci_ea_init(dev); /* Enhanced Allocation */
@@ -2604,6 +2613,7 @@ static void pci_init_capabilities(struct pci_dev *dev)
26042613
/* Buffers for saving PCIe and PCI-X capabilities */
26052614
pci_allocate_cap_save_buffers(dev);
26062615

2616+
pci_imm_ready_init(dev); /* Immediate Readiness */
26072617
pci_pm_init(dev); /* Power Management */
26082618
pci_vpd_init(dev); /* Vital Product Data */
26092619
pci_configure_ari(dev); /* Alternative Routing-ID Forwarding */

drivers/pci/quirks.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ int pcie_failed_link_retrain(struct pci_dev *dev)
105105
!pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting)
106106
return ret;
107107

108-
pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2);
109108
pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
110109
if (!(lnksta & PCI_EXP_LNKSTA_DLLLA) && pcie_lbms_seen(dev, lnksta)) {
111-
u16 oldlnkctl2 = lnkctl2;
110+
u16 oldlnkctl2;
112111

113112
pci_info(dev, "broken device, retraining non-functional downstream link at 2.5GT/s\n");
114113

114+
pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &oldlnkctl2);
115115
ret = pcie_set_target_speed(dev, PCIE_SPEED_2_5GT, false);
116116
if (ret) {
117117
pci_info(dev, "retraining failed\n");
@@ -123,6 +123,8 @@ int pcie_failed_link_retrain(struct pci_dev *dev)
123123
pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
124124
}
125125

126+
pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2);
127+
126128
if ((lnksta & PCI_EXP_LNKSTA_DLLLA) &&
127129
(lnkctl2 & PCI_EXP_LNKCTL2_TLS) == PCI_EXP_LNKCTL2_TLS_2_5GT &&
128130
pci_match_id(ids, dev)) {

include/linux/hypervisor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ static inline bool hypervisor_isolated_pci_functions(void)
3737
if (IS_ENABLED(CONFIG_S390))
3838
return true;
3939

40+
if (IS_ENABLED(CONFIG_LOONGARCH))
41+
return true;
42+
4043
return jailhouse_paravirt();
4144
}
4245

0 commit comments

Comments
 (0)