Bug 67001

Summary: pci does not allocate enough bus numbers below thunderbolt hotplug port
Product: Drivers Reporter: Andreas Noever (andreas.noever)
Component: PCIAssignee: drivers_pci (drivers_pci)
Status: NEW ---    
Severity: normal CC: dsvensson
Priority: P1    
Hardware: x86-64   
OS: Linux   
Kernel Version: v3.13-rc3 Subsystem:
Regression: No Bisected commit-id:
Attachments: 3.13-rc3 dmesg: boot, remove, disable&enable power, rescan
3.13-rc3 lspci -vv: after boot (with acpi_osi=Darwin so that firmware does not disable the controller)
3.13-rc3 lspci -vv: after boot, remove, disable&enable power, rescan
for-pci-busn-alloc-3.14: after boot, remove, disable&enable power, rescan
for-pci-busn-alloc-3.14: after boot, remove, disable&enable power, rescan, hotplug
for-pci-busn-alloc-3.14 dmesg: after boot, remove, disable&enable power, rescan, hotplug

Description Andreas Noever 2013-12-14 20:41:45 UTC
Created attachment 118411 [details]
3.13-rc3 dmesg: boot, remove, disable&enable power, rescan

I am working on a thunderbolt driver for my MacBook (where the firmeware does not handle hotplug events). The thunderbolt part is working but I am having some trouble with the pci part. After the firmware initializes the controller it looks like this (details: lspci_vv_boot):

           +-01.1-[05-9b]----00.0-[06-6b]--+-00.0-[07]----00.0  Intel Corporation DSL3510 Thunderbolt Port [Cactus Ridge]
           |                               +-03.0-[08-38]--
           |                               +-04.0-[39-69]--
           |                               +-05.0-[6a]--
           |                               \-06.0-[6b]--
6:03-6:06 are the hotplug ports and the first two have enough resources assigned.

During suspend/resume the power to 05 and everything below is cut. When I reenable power and rescan via sysfs then I get (details: lspci_vv_power)
           +-01.1-[05-9b]----00.0-[06-0b]--+-00.0-[07]----00.0  Intel Corporation DSL3510 Thunderbolt Port [Cactus Ridge]
           |                               +-03.0-[08]--
           |                               +-04.0-[09]--
           |                               +-05.0-[0a]--
           |                               \-06.0-[0b]--
Subsequent hotplug events fail with:

pciehp 0000:06:03.0:pcie24: Card present on Slot(3-1)
pci 0000:08:00.0: [8086:1549] type 01 class 0x060400
pci 0000:08:00.0: calling pci_fixup_transparent_bridge+0x0/0x30
pci 0000:08:00.0: supports D1 D2
pci 0000:08:00.0: PME# supported from D0 D1 D2 D3hot D3cold
pci 0000:08:00.0: PME# disabled
No bus number available for hot-added bridge 0000:08:00.0
pcieport 0000:06:03.0: bridge window [io  0x1000-0x0fff] to [bus 08] add_size 1000
pcieport 0000:06:03.0: res[13]=[io  0x1000-0x0fff] get_res_add_size add_size 1000
pcieport 0000:06:03.0: BAR 13: can't assign io (size 0x1000)
pcieport 0000:06:03.0: BAR 13: can't assign io (size 0x1000)
pcieport 0000:06:03.0: PCI bridge to [bus 08]
pcieport 0000:06:03.0:   bridge window [mem 0xc1e00000-0xc20fffff]
pcieport 0000:06:03.0:   bridge window [mem 0xce100000-0xce3fffff 64bit pref]
pci 0000:08:00.0: no hotplug settings from platform
pcieport 0000:08:00.0: enabling bus mastering
pcieport 0000:08:00.0: irq 56 for MSI/MSI-X

I have attached the full dmesg output of the following sequence: boot, remove 05 via sysfs (lots of warnings here), remove power, enable power, rescan 05 via sysfs. 

I have also tried to use
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-busn-alloc-3.14

After the same sequence I get (details: lspci_vv_busn):
           +-01.1-[05-9b]----00.0-[06-27]--+-00.0-[07]----00.0  Intel Corporation DSL3510 Thunderbolt Port [Cactus Ridge]
           |                               +-03.0-[08-0f]--
           |                               +-04.0-[10-17]--
           |                               +-05.0-[18-1f]--
           |                               \-06.0-[20-27]--
But then after hotplugging a device (details: lspci_vv_busn_hotplug):
           +-01.1-[05-9b]----00.0-[06-29]--+-00.0-[07]----00.0  Intel Corporation DSL3510 Thunderbolt Port [Cactus Ridge]
           |                               +-03.0-[08-11]----00.0-[09-11]----00.0-[0a-11]----00.0  Broadcom Corporation NetXtreme BCM57762 Gigabit Ethernet PCIe
           |                               +-04.0-[10-17]--
           |                               +-05.0-[18-1f]--
           |                               \-06.0-[20-27]--
Note that the bus numbers are not disjoint.

dmesg_busn contains the full dmesg output of the above sequence + a hotplug event.
Comment 1 Andreas Noever 2013-12-14 20:43:39 UTC
Created attachment 118421 [details]
3.13-rc3 lspci -vv: after boot (with acpi_osi=Darwin so that firmware does not disable the controller)
Comment 2 Andreas Noever 2013-12-14 20:44:28 UTC
Created attachment 118431 [details]
3.13-rc3 lspci -vv: after boot, remove, disable&enable power, rescan
Comment 3 Andreas Noever 2013-12-14 20:46:45 UTC
Created attachment 118441 [details]
for-pci-busn-alloc-3.14: after boot, remove, disable&enable power, rescan
Comment 4 Andreas Noever 2013-12-14 20:47:22 UTC
Created attachment 118451 [details]
for-pci-busn-alloc-3.14: after boot, remove, disable&enable power, rescan, hotplug
Comment 5 Andreas Noever 2013-12-14 20:48:17 UTC
Created attachment 118461 [details]
for-pci-busn-alloc-3.14 dmesg: after boot, remove, disable&enable power, rescan, hotplug