Skip to content

Conversation

@sdurawa
Copy link
Owner

@sdurawa sdurawa commented Oct 8, 2024

Introducing 2 commits to support PCH rootbus for Intel VMD enhancements.

Szymon Durawa added 2 commits October 8, 2024 15:17
This function is too long and needs to be shortened to make it more readable.
Certain VMD devices like 0xAD0B has two bus ranges, current implementation
supports only one range. This clean up is a prework for enablement additional
VMD bus range.

Signed-off-by: Szymon Durawa <[email protected]>
Suggested-by: Nirmal Patel <[email protected]>
Starting from 0xAD0B VMD enhacement introduces separate rootbus for PCH.
It means that all 3 MMIO BARs exposed by VMD are shared now between CPU
IOC and PCH. This patch adds PCH bus enumeration and MMIO management
for devices with VMD enhancement support.

Signed-off-by: Szymon Durawa <[email protected]>
Suggested-by: Nirmal Patel <[email protected]>
@sdurawa sdurawa marked this pull request as ready for review October 8, 2024 13:44
@sdurawa sdurawa changed the title Vmd add pch rootbus PCI: vmd: add PCH rootbus Oct 8, 2024
VMD_FEAT_BIOS_PM_QUIRK = (1 << 5),

/*
* Some client VMD devices have their VMD rootports connected to both

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nie wspominaj tutaj, że mówimy tu o "client" ponieważ nikogo to nie obchodzi. Część ludzi nie ogarnie nawet co masz na myśli.
To co jest ważne to fakty. a fakt jest taki:

"Starting from Intel Lunar Lake, VMD driver might be connected to PCH rootbus" (jeżeli dobrze pamiętam, to Lunar lake).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

* PCI_VMD_PRIMARY_PCH_BUS but original value is 0xE1 which is stored
* in vmd->busn_start_pch.
*/
if (vmd_has_pch_rootbus(vmd) && bus->number == PCI_VMD_PRIMARY_PCH_BUS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wydaje mi się, że te warunki są jednoznaczne w tym miejscu i możesz sprawdzić tylko jeden z nich.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (vmd_has_pch_rootbus(vmd) && bus->number == PCI_VMD_PRIMARY_PCH_BUS)
busnr_ecam = vmd->busn_start_pch - vmd->busn_start;
else
busnr_ecam = bus->number - vmd->busn_start;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jeżeli zachodzi koniecznośc takiego WA zdecydowanie czytelniejsze, będzie, jeżeli stworzysz pole (jeżeli dobrze rozumiem) vmd->busn_offset[2] i będziesz tam przypisywał wartość:

vmd->busn_offset[0] = bus->number;
vmd->busn_offset[1] = 0xE1;

Chodzi mi o to że nazywanie pól pod pch ogranicza rozszerzalność tego rozwiązania (jeżeli ktoś za parę lat doda inny pcie bus ciężko będzie utrzymać odpowiednie nazewnictwo).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

struct resource resources[6];
struct irq_domain *irq_domain;
struct pci_bus *bus;
struct pci_bus *bus_pch;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nie da rady zmergować busów w tablice?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dodac define na ilosc busow

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

};

/*
* Update first cfgbar range (IOC) with value stored

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nie musisz tłumaczyć kodu, każdy ogarnięty developer widzi co robisz. To co nas interesuje to dlaczego jest taka potrzeba. Najelpszy byłby link do specyfikacji jeżeli jest to PCIe spek. Pewnie nie jest.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

*
* The only way we could use a 64-bit non-prefetchable MEMBAR is
* if its address is <4GB so that we can convert it to a 32-bit
* resource. To be visible to the host OS, all VMD endpoints must

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double space.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

/*
* Align resource information the same as for vmd_configure_membar1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ten komentarz nic nie wnosi.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

* Align resource information the same as for vmd_configure_membar1
* function.
*/
static void vmd_configure_membar2(struct vmd_dev *vmd,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

te dwie funkcje vmd_configure_membar1 i vmd_configure_membar2 wydaje mi się, że można połączyć w jedną ponieważ kod jest niemal indentyczny (poza resorces, które updatujesz) oczywiście są one sobie odpowiadające więc jesteś w stanie odnosić się po indexach.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no i wtedy możesz ładnie opisać co się znajduje w poszczególnych resources (jeżeli oczywiscie merge tych funkcji jest możliwy).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

struct resource *res;
u32 upper_bits, reg;
unsigned long flags;
u64 vmd_enh_membar2_offset = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podobnie jak wyżej, proszę zmień vmd_membar2_pch_offset

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

/*
* VMD enhacement specific: pci_scan_bridge_extend() in probe.c

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skróciłbym to trochę, i na razie podkreślił że to jest te miejsce przez które robimy RFC

This is a workaround for pci_scan_bridge_extend() code.
It assigns setup as broken when primary != bus->number.
For PCH rootbus primary is not "hard-wired to 0".
To avoid this, vmd->bus_pch->number and vmd->bus_pch->primary  are updated to same value.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

#define VMCONFIG_MSI_REMAP 0x2
#define PCI_REG_VMLOCK 0x70
#define MB2_SHADOW_EN(vmlock) (vmlock & 0x2)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VMD enhacement nie zmienia prezentacji urzadzen

sdurawa added 3 commits October 15, 2024 13:44
Starting from 0xAD0B VMD enhacement introduces separate rootbus for PCH.
It means that all 3 MMIO BARs exposed by VMD are shared now between CPU
IOC and PCH. This patch adds PCH bus enumeration and MMIO management
for devices with VMD enhancement support.

Signed-off-by: Szymon Durawa <[email protected]>
Suggested-by: Nirmal Patel <[email protected]>
This function is too long and needs to be shortened to make it more readable.
Certain VMD devices like 0xAD0B has two bus ranges, current implementation
supports only one range. This clean up is a prework for enablement additional
VMD bus range.

Signed-off-by: Szymon Durawa <[email protected]>
Suggested-by: Nirmal Patel <[email protected]>
…tbus for PCH.

It means that all 3 MMIO BARs exposed by VMD are shared now between CPU
IOC and PCH. This patch adds PCH bus enumeration and MMIO management
for devices with VMD enhancement support.

Signed-off-by: Szymon Durawa <[email protected]>
Suggested-by: Nirmal Patel <[email protected]>
#define VMD_MEMBAR1 2
#define VMD_MEMBAR2 4

#define VMD_ROOTBUS_SIZE 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo VMD_ROOTBUS_COUNT

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

struct irq_domain *irq_domain;
struct pci_bus *bus;
u8 busn_start;
struct pci_bus *bus[VMD_ROOTBUS_SIZE];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can eventually consider to group it into struct but it is fine for me.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

};

enum vmd_rootbus {
VMD_ROOTBUS0,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo VMD_ROOTBUS_0, but is is fine anyway

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

* PCI_VMD_PRIMARY_PCH_BUS but original value is 0xE1 which is stored
* in vmd->busn_start[VMD_ROOTBUS1].
*/
if (vmd_has_pch_rootbus(vmd) && bus->number == PCI_VMD_PRIMARY_PCH_BUS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can detect it by:
if (&(vmd->bus[VMD_ROOTBUS1]) == bus)

and I think it is better readable, because you are not reaying on hack but on adress.
Eventually, you can consider passing enum vmd_rootbus instead of bus, and deference it here.

If you passing struct vmd_dev *vmd and passing struct pci_bus *bus placed inside vmd the struct is not mandatory because you can obtain it easy.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition is rewritten using ? operand.

unsigned char bus_number = 0;

/*
* VMD enhacement specific: for PCH rootbus, bus number is set to

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove VMD enhancement specyfic. It has nothing to do with VMD and it is not specific, it is a hack for kernel code elsewhere.

Please add reference to vmd_create_pch_bus. Simple

See comment in vmd_create_pch_bus().

Should be fine.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

vmd->busn_start[VMD_ROOTBUS1] = 225;
} else {
pci_err(dev,
"Unknown Bus Offset Setting (%d)\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Unknown Bus Offset Setting (%d)\n" is not really helpful.

What about:
Determined 3 vmd configs but VMD in PCH bus is not supported, aborting.

Probably you can find better wording, I didn't check it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}
}

static void vmd_configure_membar(struct vmd_dev *vmd,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description upon the function would be recommended and helpful.
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description added.

*/
vmd_configure_membar(vmd, VMD_MEMBAR1, VMD_RESOURCE_MEMBAR1, 0,
pch_membar1_offset, NULL);
vmd_configure_membar(vmd, VMD_MEMBAR2, VMD_RESOURCE_MEMBAR2,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don' like here is repeated initialization please consider reverting order. or use if/else

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

pci_err(dev,
"Unknown Bus Offset Setting (%d)\n",
BUS_RESTRICT_CFG(reg));
return -ENODEV;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider other error codes (in each case now -ENODEV is returned from various functions)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link

@mtkaczyk mtkaczyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please update module version
  • Please update patches author (currently it is sdurawa)

#define MB2_SHADOW_EN(vmlock) (vmlock & 0x2)

#define PCI_VMD_PRIMARY_PCH_BUS 0x80
#define PCI_REG_BUSRANGE0 0xC8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should make all defines starting with PCI_VMD or just VMD. We should avoid name confusion with different components.

If you would like to stay with PCI_* then it is not right place for those defines because they are probably global and should be placed in include/linux/pci_regs.h - we don't want that.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

#define MB2_SHADOW_SIZE 16

enum vmd_resource {
VMD_RESOURCE_CFGBAR,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VMD_RESOURCE_CFGBAR = 0 to force initialization from 0

Suggested change
VMD_RESOURCE_CFGBAR,
VMD_RESOURCE_CFGBAR = 0,

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

VMD_FEAT_HAS_BUS_RESTRICTIONS | \
VMD_FEAT_OFFSET_FIRST_VECTOR | \
VMD_FEAT_BIOS_PM_QUIRK)
VMD_FEAT_BIOS_PM_QUIRK | \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like to alligned same way as above but it could be presentation issue:

Suggested change
VMD_FEAT_BIOS_PM_QUIRK | \
VMD_FEAT_BIOS_PM_QUIRK | \

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

};

enum vmd_rootbus {
VMD_ROOTBUS_0,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VMD_ROOTBUS_0,
VMD_ROOTBUS_0 = 0,

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

struct pci_bus *bus;
u8 busn_start;
struct pci_bus *bus[VMD_ROOTBUS_COUNT];
u8 busn_start[VMD_ROOTBUS_COUNT];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is asking to be placed in structure.

struct vmd_pci_bus {
    struct pci_bus *bus;
    u8 busn_start;
Suggested change
u8 busn_start[VMD_ROOTBUS_COUNT];
struct vmd_pci_bus vmd_bus[VMD_ROOTBUS_COUNT];

but I think it is fine either way

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes here.

pci_scan_child_bus(vmd->bus);
vmd_domain_reset(vmd);
WARN(sysfs_create_link(&vmd->dev->dev.kobj,
&vmd->bus[VMD_ROOTBUS_0]->dev.kobj, "domain"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we create domain link for pch attached ROOTBUS_1?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is only required for VMD domain. When creating sys link for ROOTBUS 1 there is an error "cannot create duplicate filename '/devices/pci0000:00/0000:00:0e.0/domain'".

vmd->busn_start[VMD_ROOTBUS_1] = 225;
} else {
pci_err(dev,
"VMD Bus Restriction detected type %d,",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"VMD Bus Restriction detected type %d,",
pci_err(dev, "VMD Bus Restriction detected type %d, but PCH Rootbus is not supported, aborting.",
BUS_RESTRICT_CFG(reg));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This messages cannot be divided because kernel is not guarantying that they will be flushed together, one by one.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (!upper_bits)
flags &= ~IORESOURCE_MEM_64;

snprintf(name, sizeof(name), "VMD MEMBAR%d", membar_number/2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strncat should be avoided :)

Suggested change
snprintf(name, sizeof(name), "VMD MEMBAR%d", membar_number/2);
snprintf(name, sizeof(name), "VMD MEMBAR%d %s", membar_number / 2,
resource_number > VMD_RESOURCE_MEMBAR_2 : "PCH", "");

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with resource_number > VMD_RESOURCE_MEMBAR_2 ? "PCH":""

*/
static void vmd_configure_membar(struct vmd_dev *vmd,
enum vmd_resource resource_number,
u8 membar_number, resource_size_t start_offset,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u8 membar_number, resource_size_t start_offset,
enum vmd_resource membar_number, resource_size_t start_offset,

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

membar number does not have an enum, it is a standalone define.


if (!vmd->bus[VMD_ROOTBUS_1]) {
pci_free_resource_list(&resources_pch);
vmd_remove_irq_domain(vmd);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we? We didn't register PCH MSI yet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudn't we call pci_stop_root_bus and pci_remove_root_bus?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, irq domain cannot be removed here, I have added stopping and removig PCH bus instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants