Re: [PATCH v6 1/8] x86/hygon: Add Family 0x18 DF node enumeration
From: Borislav Petkov
Date: Tue Sep 29 2026 - 20:44:04 EST
On Mon, Sep 21, 2026 at 01:55:56PM +0800, Lin Wang wrote:
> +struct hygon_node {
> + struct pci_dev *misc;
> + struct pci_dev *link;
> + u8 socket_id;
> + u8 dfid;
> + bool is_cdd;
> +};
> +
> +struct hygon_node_cache {
> + struct hygon_node *nodes;
> + u16 num_nodes;
> + u16 num_cdd;
> + u16 num_sockets;
> +};
> +
> +struct hygon_df_id {
> + u8 socket_id;
> + u8 dfid;
> +};
> +
> +/* DF sibling device IDs used to read node identity. */
> +struct hygon_df_cfg {
> + u16 f1_id;
> + u16 f5_id;
> +};
> +
> +/* DF misc (F3) device IDs for all supported Hygon Family 0x18 models. */
> +static const struct pci_device_id hygon_nb_misc_ids[] = {
> + { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_HYGON_18H_DF_F3) },
> + { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_HYGON_18H_M04H_DF_F3) },
> + { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_HYGON_18H_M05H_DF_F3) },
> + {}
> +};
> +
> +/* DF link (F4) device IDs for supported models. */
> +static const struct pci_device_id hygon_nb_link_ids[] = {
> + { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_HYGON_18H_DF_F4) },
> + { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_HYGON_18H_M04H_DF_F4) },
> + { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_HYGON_18H_M05H_DF_F4) },
> + {}
> +};
> +
> +static const struct hygon_df_cfg hygon_m04_df_cfg __initconst = {
> + .f1_id = PCI_DEVICE_ID_HYGON_18H_M04H_DF_F1,
> +};
> +
> +static const struct hygon_df_cfg hygon_m05_df_cfg __initconst = {
> + .f1_id = PCI_DEVICE_ID_HYGON_18H_M05H_DF_F1,
> +};
> +
> +static const struct hygon_df_cfg hygon_m06_m08_df_cfg __initconst = {
> + .f1_id = PCI_DEVICE_ID_HYGON_18H_M05H_DF_F1,
> + .f5_id = PCI_DEVICE_ID_HYGON_18H_M06H_DF_F5,
> +};
> +
> +static const struct x86_cpu_id hygon_df_cpuids[] __initconst = {
> + X86_MATCH_VENDOR_FAM_MODEL(HYGON, 0x18, 0x04, &hygon_m04_df_cfg),
> + X86_MATCH_VENDOR_FAM_MODEL(HYGON, 0x18, 0x05, &hygon_m05_df_cfg),
> + X86_MATCH_VENDOR_FAM_MODEL(HYGON, 0x18, 0x06, &hygon_m06_m08_df_cfg),
> + X86_MATCH_VENDOR_FAM_MODEL(HYGON, 0x18, 0x07, &hygon_m06_m08_df_cfg),
> + X86_MATCH_VENDOR_FAM_MODEL(HYGON, 0x18, 0x08, &hygon_m06_m08_df_cfg),
> + {}
> +};
> +
> +static struct hygon_node_cache hygon_cache;
> +
> +/*
> + * Iterate Hygon PCI devices, returning the next one that matches @ids.
> + * Follows the pci_get_device() convention: @from is consumed (its
> + * reference is dropped) and the returned device has an elevated
> + * reference count.
> + */
> +static struct pci_dev * __init next_hygon_dev(struct pci_dev *from,
> + const struct pci_device_id *ids)
> +{
> + while ((from = pci_get_device(PCI_VENDOR_ID_HYGON, PCI_ANY_ID, from))) {
> + if (pci_match_id(ids, from))
> + return from;
> + }
> +
> + return NULL;
> +}
> +
> +/*
> + * Find the DF link (function 4) sibling of a DF misc (function 3)
> + * device. Both functions share the same PCI bus and slot.
> + */
> +static struct pci_dev * __init hygon_get_link(struct pci_dev *misc)
> +{
> + struct pci_dev *link;
> +
> + link = pci_get_domain_bus_and_slot(pci_domain_nr(misc->bus),
> + misc->bus->number,
> + PCI_DEVFN(PCI_SLOT(misc->devfn),
> + HYGON_DF_F4));
> + if (!link)
> + return NULL;
> +
> + if (!pci_match_id(hygon_nb_link_ids, link)) {
> + pci_dev_put(link);
> + return NULL;
> + }
> +
> + return link;
> +}
So all your local structs and functions - above and below, they don't really
need the "hygon_" prefix. This way, for one, you can know immediately from the
name whether it is a local or an exported entity and, two, you're going to
have a lot smaller text, much easier to read and so on.
Other than that, that patch LGTM.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette