Skip to contentSkip to conversation

MFD: intel_pmt: Split OOBMSM from intel_pmt driver

PATCH Superseded David E. Box 5 participants 16 messages Jun 17, 2021 – Jul 1, 2021 2 messages not in the archive

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover MFD: intel_pmt: Split OOBMSM from intel_pmt driver

Most of the devices in the intel_pmt driver are PMT only devices. However, the Out of Band Management Services Module (OOBMSM) can also be used access non-PMT devices. In order to better support this without the confusion of a dependency on MFD_INTEL_PMT, this patch set rewrites the intel_pmt driver to split the functionality into 3 components:

1. intel_pmt - driver for PMT only devices
2. intel-oobmsm - driver for devices using the OOBMSM IP which can support multiple types of capabilities, including PMT
3. intel-extended-cap - symbols to handle adding platform device for both drivers

Additionally, this patch set provides additional DVSEC macros in the PCI header as well as support for reading capabilities from a VSEC structure.

Patch 1 - Adds PCI defines for DVSEC registers
Patch 2 - Removes OOBMSM from intel_pmt and creates intel-extended-cap.c
support the creation of platform devices for capabilities from both intel_pmt and intel-oobmsm (Patch 3)
Patch 2 - Creates a separate driver for OOBMSM
Patch 3 - Adds support for reading capabilities from PCIe VSEC structures

For submission through MFD branch.

David E. Box (4):
PCI: Add #defines for accessing PCIE DVSEC fields
MFD: intel_pmt: Remove OOBMSM device for placement in own driver
MFD: Add the Intel Out of Band Management Services Module (OOBMSM)
driver
MFD: intel-extended-cap: Add support for PCIe VSEC structures

 MAINTAINERS                                |   2 +
 drivers/mfd/Kconfig                        |  15 ++
 drivers/mfd/Makefile                       |   2 +
 drivers/mfd/intel_extended_caps.c          | 267 +++++++++++++++++++++
 drivers/mfd/intel_extended_caps.h          |  40 +++
 drivers/mfd/intel_oobmsm.c                 |  61 +++++
 drivers/mfd/intel_pmt.c                    | 198 ++-------------
 drivers/platform/x86/Kconfig               |   4 +-
 drivers/platform/x86/intel_pmt_crashlog.c  |   2 +-
 drivers/platform/x86/intel_pmt_telemetry.c |   2 +-
 include/uapi/linux/pci_regs.h              |   4 +
 11 files changed, 409 insertions(+), 188 deletions(-)
 create mode 100644 drivers/mfd/intel_extended_caps.c
 create mode 100644 drivers/mfd/intel_extended_caps.h
 create mode 100644 drivers/mfd/intel_oobmsm.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/4 PCI: Add #defines for accessing PCIE DVSEC fields

Add #defines for accessing Vendor ID, Revision, Length, and ID offsets in the Designated Vendor Specific Extended Capability (DVSEC). Defined in PCIe r5.0, sec 7.9.6.

---
 include/uapi/linux/pci_regs.h | 4 ++++
 1 file changed, 4 insertions(+)
include/uapi/linux/pci_regs.h +4 -0
index e709ae8235e7..57ee51f19283 100644
@@ -1080,7 +1080,11 @@
 
 /* Designated Vendor-Specific (DVSEC, PCI_EXT_CAP_ID_DVSEC) */
 #define PCI_DVSEC_HEADER1		0x4 /* Designated Vendor-Specific Header1 */
+#define  PCI_DVSEC_HEADER1_VID(x)	((x) & 0xffff)
+#define  PCI_DVSEC_HEADER1_REV(x)	(((x) >> 16) & 0xf)
+#define  PCI_DVSEC_HEADER1_LEN(x)	(((x) >> 20) & 0xfff)
 #define PCI_DVSEC_HEADER2		0x8 /* Designated Vendor-Specific Header2 */
+#define  PCI_DVSEC_HEADER2_ID(x)		((x) & 0xffff)
 
 /* Data Link Feature */
 #define PCI_DLF_CAP		0x04	/* Capabilities Register */
Signature · 1 line
2.25.1
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] PCI: Add #defines for accessing PCIE DVSEC fields

[+cc Dan, Jonathan]

Quoted 5 lines · David E. Box

Add #defines for accessing Vendor ID, Revision, Length, and ID offsets in the Designated Vendor Specific Extended Capability (DVSEC). Defined in PCIe r5.0, sec 7.9.6.

I don't have time right now to really look at the intel_extended_caps.c patch [1], but I wonder if there's anything there that could be abstracted and shared with CXL, etc? If not, no worries.

[1] https://lore.kernel.org/r/[email protected]

Quoted 23 lines
---
 include/uapi/linux/pci_regs.h | 4 ++++
 1 file changed, 4 insertions(+)
include/uapi/linux/pci_regs.h +4 -0
index e709ae8235e7..57ee51f19283 100644
@@ -1080,7 +1080,11 @@
 
 /* Designated Vendor-Specific (DVSEC, PCI_EXT_CAP_ID_DVSEC) */
 #define PCI_DVSEC_HEADER1		0x4 /* Designated Vendor-Specific Header1 */
+#define  PCI_DVSEC_HEADER1_VID(x)	((x) & 0xffff)
+#define  PCI_DVSEC_HEADER1_REV(x)	(((x) >> 16) & 0xf)
+#define  PCI_DVSEC_HEADER1_LEN(x)	(((x) >> 20) & 0xfff)
 #define PCI_DVSEC_HEADER2		0x8 /* Designated Vendor-Specific Header2 */
+#define  PCI_DVSEC_HEADER2_ID(x)		((x) & 0xffff)
 
 /* Data Link Feature */
 #define PCI_DLF_CAP		0x04	/* Capabilities Register */
Signature · 1 line
2.25.1
#3 lore raw

PATCH 2/4 MFD: intel_pmt: Remove OOBMSM device

In reply to David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management Services Module (OOBMSM) is actually not a PMT dedicated device. It can also be used to describe non-PMT capabilities. Like PMT, these capabilities are also enumerated using PCIe Vendor Specific registers in config space. In order to better support these devices without the confusion of a dependency on MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be later placed in its own driver. Since much of the same code will be used by intel_pmt and the new driver, create a new file with symbols to be used by both.

While performing this split we need to also handle the creation of platform devices for the non-PMT capabilities. Currently PMT devices are named by their capability (e.g. pmt_telemetry). Instead, generically name them by their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be created automatically. However, to ensure that unsupported devices aren't created, use an allow list to specify supported capabilities.

---
 MAINTAINERS                                |   1 +
 drivers/mfd/Kconfig                        |   4 +
 drivers/mfd/Makefile                       |   1 +
 drivers/mfd/intel_extended_caps.c          | 208 +++++++++++++++++++++
 drivers/mfd/intel_extended_caps.h          |  40 ++++
 drivers/mfd/intel_pmt.c                    | 198 ++------------------
 drivers/platform/x86/intel_pmt_crashlog.c  |   2 +-
 drivers/platform/x86/intel_pmt_telemetry.c |   2 +-
 8 files changed, 270 insertions(+), 186 deletions(-)
 create mode 100644 drivers/mfd/intel_extended_caps.c
 create mode 100644 drivers/mfd/intel_extended_caps.h
MAINTAINERS +1 -0
index bc0ceef87b73..ebdc2a0f794b 100644
@@ -9355,6 +9355,7 @@ F:	include/linux/mfd/intel_soc_pmic*
 INTEL PMT DRIVER
 M:	"David E. Box" <[email protected]>
 S:	Maintained
+F:	drivers/mfd/intel_extended_cap.c
 F:	drivers/mfd/intel_pmt.c
 F:	drivers/platform/x86/intel_pmt_*
 
drivers/mfd/Kconfig +4 -0
index 5c7f2b100191..4dde8e223a9e 100644
@@ -673,10 +673,14 @@ config MFD_INTEL_PMC_BXT
 	  Register and P-unit access. In addition this creates devices
 	  for iTCO watchdog and telemetry that are part of the PMC.
 
+config MFD_INTEL_EXTENDED_CAPS
+	tristate
+
 config MFD_INTEL_PMT
 	tristate "Intel Platform Monitoring Technology (PMT) support"
 	depends on PCI
 	select MFD_CORE
+	select MFD_INTEL_EXTENDED_CAPS
 	help
 	  The Intel Platform Monitoring Technology (PMT) is an interface that
 	  provides access to hardware monitor registers. This driver supports
drivers/mfd/Makefile +1 -0
index 4f6d2b8a5f76..7fa35399ec76 100644
@@ -209,6 +209,7 @@ obj-$(CONFIG_MFD_AT91_USART)	+= at91-usart.o
 obj-$(CONFIG_MFD_ATMEL_FLEXCOM)	+= atmel-flexcom.o
 obj-$(CONFIG_MFD_ATMEL_HLCDC)	+= atmel-hlcdc.o
 obj-$(CONFIG_MFD_ATMEL_SMC)	+= atmel-smc.o
+obj-$(CONFIG_MFD_INTEL_EXTENDED_CAPS)	+= intel_extended_caps.o
 obj-$(CONFIG_MFD_INTEL_LPSS)	+= intel-lpss.o
 obj-$(CONFIG_MFD_INTEL_LPSS_PCI)	+= intel-lpss-pci.o
 obj-$(CONFIG_MFD_INTEL_LPSS_ACPI)	+= intel-lpss-acpi.o
drivers/mfd/intel_extended_caps.c new file +208 -0

208 lines not on this page · raw message

drivers/mfd/intel_extended_caps.h new file +40 -0
new file mode 100644
index 000000000000..c6722d4cb5e3
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef INTEL_EXTENDED_CAPS_H
+#define INTEL_EXTENDED_CAPS_H
+
+/* Intel Extended Features */
+#define INTEL_EXT_CAP_ID_TELEMETRY	2
+#define INTEL_EXT_CAP_ID_WATCHER	3
+#define INTEL_EXT_CAP_ID_CRASHLOG	4
+
+struct intel_ext_cap_header {
+	u8	rev;
+	u16	length;
+	u16	id;
+	u8	num_entries;
+	u8	entry_size;
+	u8	tbir;
+	u32	offset;
+};
+
+enum intel_ext_cap_quirks {
+	/* Watcher capability not supported */
+	EXT_CAP_QUIRK_NO_WATCHER	= BIT(0),
+
+	/* Crashlog capability not supported */
+	EXT_CAP_QUIRK_NO_CRASHLOG	= BIT(1),
+
+	/* Use shift instead of mask to read discovery table offset */
+	EXT_CAP_QUIRK_TABLE_SHIFT	= BIT(2),
+
+	/* DVSEC not present (provided in driver data) */
+	EXT_CAP_QUIRK_NO_DVSEC	= BIT(3),
+};
+
+struct intel_ext_cap_platform_info {
+	unsigned long quirks;
+	struct intel_ext_cap_header **capabilities;
+};
+
+int intel_ext_cap_probe(struct pci_dev *pdev, struct intel_ext_cap_platform_info *info);
+#endif
drivers/mfd/intel_pmt.c +14 -184

244 lines not on this page · raw message

drivers/platform/x86/intel_pmt_crashlog.c +1 -1
index 92d315a16cfd..6662454af5bf 100644
@@ -17,7 +17,7 @@
 
 #include "intel_pmt_class.h"
 
-#define DRV_NAME		"pmt_crashlog"
+#define DRV_NAME		"intel_extnd_cap_4"
 
 /* Crashlog discovery header types */
 #define CRASH_TYPE_OOBMSM	1
drivers/platform/x86/intel_pmt_telemetry.c +1 -1
index 9b95ef050457..f281d1d71058 100644
@@ -17,7 +17,7 @@
 
 #include "intel_pmt_class.h"
 
-#define TELEM_DEV_NAME		"pmt_telemetry"
+#define TELEM_DEV_NAME		"intel_extnd_cap_2"
 
 #define TELEM_SIZE_OFFSET	0x0
 #define TELEM_GUID_OFFSET	0x4
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

Quoted 17 lines · David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management Services Module (OOBMSM) is actually not a PMT dedicated device. It can also be used to describe non-PMT capabilities. Like PMT, these capabilities are also enumerated using PCIe Vendor Specific registers in config space. In order to better support these devices without the confusion of a dependency on MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be later placed in its own driver. Since much of the same code will be used by intel_pmt and the new driver, create a new file with symbols to be used by both.

While performing this split we need to also handle the creation of platform devices for the non-PMT capabilities. Currently PMT devices are named by their capability (e.g. pmt_telemetry). Instead, generically name them by their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be created automatically. However, to ensure that unsupported devices aren't created, use an allow list to specify supported capabilities.

Quoted 6 lines
---
 MAINTAINERS                                |   1 +
 drivers/mfd/Kconfig                        |   4 +
 drivers/mfd/Makefile                       |   1 +
 drivers/mfd/intel_extended_caps.c          | 208 +++++++++++++++++++++

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

I suggest Andy should also be on Cc.

Quoted 7 lines
 drivers/mfd/intel_extended_caps.h          |  40 ++++
 drivers/mfd/intel_pmt.c                    | 198 ++------------------
 drivers/platform/x86/intel_pmt_crashlog.c  |   2 +-
 drivers/platform/x86/intel_pmt_telemetry.c |   2 +-
 8 files changed, 270 insertions(+), 186 deletions(-)
 create mode 100644 drivers/mfd/intel_extended_caps.c
 create mode 100644 drivers/mfd/intel_extended_caps.h
Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#5 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

Quoted 40 lines · Lee Jones
Quoted 30 lines · David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management Services
Module (OOBMSM) is actually not a PMT dedicated device. It can also be used
to describe non-PMT capabilities. Like PMT, these capabilities are also
enumerated using PCIe Vendor Specific registers in config space. In order
to better support these devices without the confusion of a dependency on
MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be
later placed in its own driver. Since much of the same code will be used by
intel_pmt and the new driver, create a new file with symbols to be used by
both.

While performing this split we need to also handle the creation of platform
devices for the non-PMT capabilities. Currently PMT devices are named by
their capability (e.g. pmt_telemetry). Instead, generically name them by
their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be
created automatically.  However, to ensure that unsupported devices aren't
created, use an allow list to specify supported capabilities.

Quoted 7 lines

---
 MAINTAINERS                                |   1 + drivers/mfd/Kconfig                        |   4 + drivers/mfd/Makefile                       |   1 + drivers/mfd/intel_extended_caps.c          | 208
+++++++++++++++++++++

Quoted 2 lines

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

None of the cell drivers are in MFD, only the PCI drivers from which the cells are created. I understood that these should be in MFD. But moving it to drivers/platform/x86 would be fine with me. That keeps the code together in the same subsystem. Comment from Hans or Andy?

Quoted 12 lines

I suggest Andy should also be on Cc.

Quoted 8 lines

 drivers/mfd/intel_extended_caps.h          |  40 ++++ drivers/mfd/intel_pmt.c                    | 198 ++---------------
---
 drivers/platform/x86/intel_pmt_crashlog.c  |   2 +- drivers/platform/x86/intel_pmt_telemetry.c |   2 +-

 8 files changed, 270 insertions(+), 186 deletions(-)

 create mode 100644 drivers/mfd/intel_extended_caps.c create mode 100644 drivers/mfd/intel_extended_caps.h

#6 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

Quoted 41 lines · David E. Box
Quoted 40 lines · Lee Jones
Quoted 37 lines · David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management Services
Module (OOBMSM) is actually not a PMT dedicated device. It can also be used
to describe non-PMT capabilities. Like PMT, these capabilities are also
enumerated using PCIe Vendor Specific registers in config space. In order
to better support these devices without the confusion of a dependency on
MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be
later placed in its own driver. Since much of the same code will be used by
intel_pmt and the new driver, create a new file with symbols to be used by
both.

While performing this split we need to also handle the creation of platform
devices for the non-PMT capabilities. Currently PMT devices are named by
their capability (e.g. pmt_telemetry). Instead, generically name them by
their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be
created automatically.  However, to ensure that unsupported devices aren't
created, use an allow list to specify supported capabilities.

---
 MAINTAINERS                                |   1 + drivers/mfd/Kconfig                        |   4 + drivers/mfd/Makefile                       |   1 + drivers/mfd/intel_extended_caps.c          | 208
+++++++++++++++++++++

Quoted 7 lines
Quoted 2 lines

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

None of the cell drivers are in MFD, only the PCI drivers from which the cells are created. I understood that these should be in MFD. But moving it to drivers/platform/x86 would be fine with me. That keeps the code together in the same subsystem. Comment from Hans or Andy?

You don't need to move everything there. If a driver uses the MFD API (like intel_pmt.c does), it can stay. But all of this PCI/hardware/ platform specific capability craziness has no place here AFAICT.

Quoted 13 lines
Quoted 11 lines

I suggest Andy should also be on Cc.

Quoted 8 lines

 drivers/mfd/intel_extended_caps.h          |  40 ++++ drivers/mfd/intel_pmt.c                    | 198 ++---------------
---
 drivers/platform/x86/intel_pmt_crashlog.c  |   2 +- drivers/platform/x86/intel_pmt_telemetry.c |   2 +-

 8 files changed, 270 insertions(+), 186 deletions(-)

 create mode 100644 drivers/mfd/intel_extended_caps.c create mode 100644 drivers/mfd/intel_extended_caps.h

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#7 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

In reply to David E. Box

Hi,

Quoted 41 lines · David E. Box
Quoted 40 lines · Lee Jones
Quoted 37 lines · David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management Services
Module (OOBMSM) is actually not a PMT dedicated device. It can also be used
to describe non-PMT capabilities. Like PMT, these capabilities are also
enumerated using PCIe Vendor Specific registers in config space. In order
to better support these devices without the confusion of a dependency on
MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be
later placed in its own driver. Since much of the same code will be used by
intel_pmt and the new driver, create a new file with symbols to be used by
both.

While performing this split we need to also handle the creation of platform
devices for the non-PMT capabilities. Currently PMT devices are named by
their capability (e.g. pmt_telemetry). Instead, generically name them by
their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be
created automatically.  However, to ensure that unsupported devices aren't
created, use an allow list to specify supported capabilities.

---
 MAINTAINERS                                |   1 + drivers/mfd/Kconfig                        |   4 + drivers/mfd/Makefile                       |   1 + drivers/mfd/intel_extended_caps.c          | 208
+++++++++++++++++++++

Quoted 7 lines
Quoted 2 lines

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

None of the cell drivers are in MFD, only the PCI drivers from which the cells are created. I understood that these should be in MFD. But moving it to drivers/platform/x86 would be fine with me. That keeps the code together in the same subsystem. Comment from Hans or Andy?

I'm fine with moving everything to drivers/platform/x86, but AFAIK usually the actual code which has the MFD cells and creates the child devices usually lives under drivers/mfd

Regards,

Hans

Quoted 15 lines
Quoted 13 lines

I suggest Andy should also be on Cc.

Quoted 8 lines

 drivers/mfd/intel_extended_caps.h          |  40 ++++ drivers/mfd/intel_pmt.c                    | 198 ++---------------
---
 drivers/platform/x86/intel_pmt_crashlog.c  |   2 +- drivers/platform/x86/intel_pmt_telemetry.c |   2 +-

 8 files changed, 270 insertions(+), 186 deletions(-)

 create mode 100644 drivers/mfd/intel_extended_caps.c create mode 100644 drivers/mfd/intel_extended_caps.h

#8 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

Quoted 47 lines · Hans de Goede

Hi,

Quoted 44 lines · David E. Box
Quoted 42 lines · Lee Jones
Quoted 30 lines · David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management Services
Module (OOBMSM) is actually not a PMT dedicated device. It can also be used
to describe non-PMT capabilities. Like PMT, these capabilities are also
enumerated using PCIe Vendor Specific registers in config space. In order
to better support these devices without the confusion of a dependency on
MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be
later placed in its own driver. Since much of the same code will be used by
intel_pmt and the new driver, create a new file with symbols to be used by
both.

While performing this split we need to also handle the creation of platform
devices for the non-PMT capabilities. Currently PMT devices are named by
their capability (e.g. pmt_telemetry). Instead, generically name them by
their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be
created automatically.  However, to ensure that unsupported devices aren't
created, use an allow list to specify supported capabilities.

Quoted 7 lines

---
 MAINTAINERS                                |   1 + drivers/mfd/Kconfig                        |   4 + drivers/mfd/Makefile                       |   1 + drivers/mfd/intel_extended_caps.c          | 208
+++++++++++++++++++++

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

Quoted 8 lines
Quoted 4 lines

None of the cell drivers are in MFD, only the PCI drivers from which the cells are created. I understood that these should be in MFD. But moving it to drivers/platform/x86 would be fine with me. That keeps the code together in the same subsystem. Comment from Hans or Andy?

I'm fine with moving everything to drivers/platform/x86, but AFAIK usually the actual code which has the MFD cells and creates the child devices usually lives under drivers/mfd

Correct. It must.

No MFD API users outside of drivers/mfd please.

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

A message that is not in the archive (sent off-list or not yet received): CAHp75Vfn6GKSj6USUPEWiPdhWRYcJbirqhU6aOeB4gruekmocg@mail.gmail.com

#10 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

Quoted 60 lines · Andy Shevchenko
Quoted 58 lines · Lee Jones
Quoted 55 lines · Hans de Goede

Hi,

Quoted 41 lines · David E. Box
Quoted 40 lines · Lee Jones
Quoted 37 lines · David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management Services
Module (OOBMSM) is actually not a PMT dedicated device. It can also be used
to describe non-PMT capabilities. Like PMT, these capabilities are also
enumerated using PCIe Vendor Specific registers in config space. In order
to better support these devices without the confusion of a dependency on
MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be
later placed in its own driver. Since much of the same code will be used by
intel_pmt and the new driver, create a new file with symbols to be used by
both.

While performing this split we need to also handle the creation of platform
devices for the non-PMT capabilities. Currently PMT devices are named by
their capability (e.g. pmt_telemetry). Instead, generically name them by
their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be
created automatically. However, to ensure that unsupported devices aren't
created, use an allow list to specify supported capabilities.

---
 MAINTAINERS                                |   1 +
 drivers/mfd/Kconfig                        |   4 +
 drivers/mfd/Makefile                       |   1 +
 drivers/mfd/intel_extended_caps.c          | 208

+++++++++++++++++++++

Quoted 7 lines
Quoted 2 lines

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

None of the cell drivers are in MFD, only the PCI drivers from which the cells are created. I understood that these should be in MFD. But moving it to drivers/platform/x86 would be fine with me. That keeps the code together in the same subsystem. Comment from Hans or Andy?

I'm fine with moving everything to drivers/platform/x86, but AFAIK usually the actual code which has the MFD cells and creates the child devices usually lives under drivers/mfd

Quoted 5 lines
Quoted 1 line

Correct. It must.

It’s definitely not the first time you are talking about, but it may be the first time I asked why it’s not enforced overall. Last time I have checked it was like 5-7 MFD uses outside the MFD folder. Are you going to fix that?

Because I can't NACK patches that weren't sent to me. :)

I'll probably look into 'fixing' it when I get some free time.

Quoted 1 line
Quoted 1 line

No MFD API users outside of drivers/mfd please.

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

A message that is not in the archive (sent off-list or not yet received): CAHp75VdmnRJKSBZ8dmU=7XsGOZ-wX6EpZhtC3X6JEE0mz-UJNg@mail.gmail.com

#12 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

Quoted 80 lines · Andy Shevchenko
Quoted 78 lines · Lee Jones
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Lee Jones
Quoted 2 lines · Hans de Goede

Hi,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · David E. Box
Quoted 6 lines · Lee Jones
Quoted 5 lines · David E. Box
Quoted 4 lines

Unlike the other devices in intel_pmt, the Out of Band Management Services
Module (OOBMSM) is actually not a PMT dedicated device. It can

also

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

be used
to describe non-PMT capabilities. Like PMT, these capabilities

are

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

also
enumerated using PCIe Vendor Specific registers in config space.

In

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

order
to better support these devices without the confusion of a dependency on
MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it can be
later placed in its own driver. Since much of the same code will

be

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

used by
intel_pmt and the new driver, create a new file with symbols to

be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

used by
both.

While performing this split we need to also handle the creation

of

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

platform
devices for the non-PMT capabilities. Currently PMT devices are named by
their capability (e.g. pmt_telemetry). Instead, generically name them by
their capability ID (e.g. intel_extnd_cap_2). This allows the IDs to be
created automatically. However, to ensure that unsupported

devices

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

aren't
created, use an allow list to specify supported capabilities.

---
 MAINTAINERS                                |   1 +
 drivers/mfd/Kconfig                        |   4 +
 drivers/mfd/Makefile                       |   1 +
 drivers/mfd/intel_extended_caps.c          | 208

+++++++++++++++++++++

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

None of the cell drivers are in MFD, only the PCI drivers from

which

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the cells are created. I understood that these should be in MFD.

But

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

moving it to drivers/platform/x86 would be fine with me. That

keeps the

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

code together in the same subsystem. Comment from Hans or Andy?

I'm fine with moving everything to drivers/platform/x86, but AFAIK usually the actual code which has the MFD cells and creates the child devices usually lives under drivers/mfd

Correct. It must.

It’s definitely not the first time you are talking about, but it may be

the

Quoted 1 line

first time I asked why it’s not enforced overall. Last time I have

checked

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

it was like 5-7 MFD uses outside the MFD folder. Are you going to fix

that?

Because I can't NACK patches that weren't sent to me. :)

Hint: you may add regexp match to the maintainers database and you will see them more often

Good idea. I'll add it to my TODO.

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#13 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

In reply to Lee Jones
Quoted 69 lines · Lee Jones
Quoted 67 lines · Hans de Goede

Hi,

Quoted 63 lines · David E. Box
Quoted 52 lines · Lee Jones
Quoted 42 lines · David E. Box

Unlike the other devices in intel_pmt, the Out of Band Management
Services
Module (OOBMSM) is actually not a PMT dedicated device. It can also
be used
to describe non-PMT capabilities. Like PMT, these capabilities are
also
enumerated using PCIe Vendor Specific registers in config space. In
order
to better support these devices without the confusion of a dependency on
MFD_INTEL_PMT, remove the OOBMSM device from intel_pmt so that it
can be
later placed in its own driver. Since much of the same code will be
used by
intel_pmt and the new driver, create a new file with symbols to be
used by
both.

While performing this split we need to also handle the creation of
platform
devices for the non-PMT capabilities. Currently PMT devices are
named by
their capability (e.g. pmt_telemetry). Instead, generically name
them by
their capability ID (e.g. intel_extnd_cap_2). This allows the IDs
to be
created automatically.  However, to ensure that unsupported devices
aren't
created, use an allow list to specify supported capabilities.

Quoted 7 lines

---
 MAINTAINERS                                |   1 + drivers/mfd/Kconfig                        |   4 + drivers/mfd/Makefile                       |   1 + drivers/mfd/intel_extended_caps.c          | 208
+++++++++++++++++++++

Quoted 2 lines

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

None of the cell drivers are in MFD, only the PCI drivers from which
the cells are created. I understood that these should be in MFD. But
moving it to drivers/platform/x86 would be fine with me. That keeps the
code together in the same subsystem. Comment from Hans or Andy?

Quoted 8 lines
Quoted 3 lines

I'm fine with moving everything to drivers/platform/x86, but AFAIK usually the actual code which has the MFD cells and creates the child devices usually lives under drivers/mfd

Correct.  It must.

No MFD API users outside of drivers/mfd please.

No problem. But these patches are not child device drivers. They take the existing intel_pmt MFD code and split it from the device driver (similar to how intel-lpss core code is split from the acpi and pci bus drivers). There are 2 drivers now, PMT-only and OOBMSM, that use a common MFD API. This is why they all reside in MFD in this patchset. But I could move the API callers to platform/x86.

But I'd like feedback on whether this split is even needed. I'm trying to manage the fact that one of the devices in intel_pmt will now need support for new, non-PMT, child devices. So there would be a mismatch between what the driver and Kconfig are named vs what it actually supports. I considered adding all the new cells to intel_pmt and renaming the driver to something more generic, but I understand this will be messy for OSVs managing Kconfig options. Thanks.

David

#14 lore raw

Re: [PATCH 2/4] MFD: intel_pmt: Remove OOBMSM device

In reply to David E. Box
Quoted 2 lines · David E. Box
Quoted 1 line · Lee Jones

On Thu, 17 Jun 2021, David E. Box wrote:

...

Quoted 7 lines
Quoted 2 lines

Please consider moving this <whatever this is> out to either drivers/pci or drivers/platform/x86.

None of the cell drivers are in MFD, only the PCI drivers from which the cells are created. I understood that these should be in MFD. But moving it to drivers/platform/x86 would be fine with me. That keeps the code together in the same subsystem. Comment from Hans or Andy?

I'm fine with the PDx86 location, but please consider moving PMT stuff under drivers/platform/x86/intel/pmt/.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#15 lore raw

PATCH 3/4 MFD: Intel Out of Band Management Services Module (OOBMSM) driver

In reply to David E. Box

The Intel Out of Band Management Services Module (OOBMSM) is a device that provides access to Intel capabilities described in PCIE vendor specific extended capability registers (both VSEC and DVSEC). These capabilities include features like Intel Platform Monitoring Technology as well as others that are not supported by the intel_pmt driver. Add a driver for creating platform devices for these capabilities coming from OOBMSM.

---
 MAINTAINERS                  |  1 +
 drivers/mfd/Kconfig          | 11 +++++++
 drivers/mfd/Makefile         |  1 +
 drivers/mfd/intel_oobmsm.c   | 61 ++++++++++++++++++++++++++++++++++++
 drivers/platform/x86/Kconfig |  4 +--
 5 files changed, 76 insertions(+), 2 deletions(-)
 create mode 100644 drivers/mfd/intel_oobmsm.c
MAINTAINERS +1 -0
index ebdc2a0f794b..0961e3f89497 100644
@@ -9356,6 +9356,7 @@ INTEL PMT DRIVER
 M:	"David E. Box" <[email protected]>
 S:	Maintained
 F:	drivers/mfd/intel_extended_cap.c
+F:	drivers/mfd/intel_oobmsm.c
 F:	drivers/mfd/intel_pmt.c
 F:	drivers/platform/x86/intel_pmt_*
 
drivers/mfd/Kconfig +11 -0
index 4dde8e223a9e..269312de2666 100644
@@ -687,6 +687,17 @@ config MFD_INTEL_PMT
 	  Telemetry, Watcher, and Crashlog PMT capabilities/devices for
 	  platforms starting from Tiger Lake.
 
+config MFD_INTEL_OOBMSM
+	tristate "Intel Out Of Band Management Services Module (OOBMSM) support"
+	depends on PCI
+	select MFD_INTEL_EXTENDED_CAPS
+	help
+	  The Intel Out of Band Management Service Module driver is used to
+	  enumerate auxiliary platform features described in both Vendor
+	  Specific and Designated Vendor Specific PCIe config space. Supported
+	  features include Intel Platform Monitoring Technology (PMT) as well
+	  as other non-PMT capabilities.
+
 config MFD_IPAQ_MICRO
 	bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support"
 	depends on SA1100_H3100 || SA1100_H3600
drivers/mfd/Makefile +1 -0
index 7fa35399ec76..50fa38810bbd 100644
@@ -213,6 +213,7 @@ obj-$(CONFIG_MFD_INTEL_EXTENDED_CAPS)	+= intel_extended_caps.o
 obj-$(CONFIG_MFD_INTEL_LPSS)	+= intel-lpss.o
 obj-$(CONFIG_MFD_INTEL_LPSS_PCI)	+= intel-lpss-pci.o
 obj-$(CONFIG_MFD_INTEL_LPSS_ACPI)	+= intel-lpss-acpi.o
+obj-$(CONFIG_MFD_INTEL_OOBMSM)	+= intel_oobmsm.o
 obj-$(CONFIG_MFD_INTEL_PMC_BXT)	+= intel_pmc_bxt.o
 obj-$(CONFIG_MFD_INTEL_PMT)	+= intel_pmt.o
 obj-$(CONFIG_MFD_PALMAS)	+= palmas.o
drivers/mfd/intel_oobmsm.c new file +61 -0

61 lines not on this page · raw message

drivers/platform/x86/Kconfig +2 -2
index 60592fb88e7a..4dd3af9f848e 100644
@@ -1226,7 +1226,7 @@ config INTEL_PMT_CLASS
 
 config INTEL_PMT_TELEMETRY
 	tristate "Intel Platform Monitoring Technology (PMT) Telemetry driver"
-	depends on MFD_INTEL_PMT
+	depends on MFD_INTEL_PMT || MFD_INTEL_OOBMSM
 	select INTEL_PMT_CLASS
 	help
 	  The Intel Platform Monitory Technology (PMT) Telemetry driver provides
@@ -1238,7 +1238,7 @@ config INTEL_PMT_TELEMETRY
 
 config INTEL_PMT_CRASHLOG
 	tristate "Intel Platform Monitoring Technology (PMT) Crashlog driver"
-	depends on MFD_INTEL_PMT
+	depends on MFD_INTEL_PMT || MFD_INTEL_OOBMSM
 	select INTEL_PMT_CLASS
 	help
 	  The Intel Platform Monitoring Technology (PMT) crashlog driver provides
Signature · 1 line
2.25.1
#16 lore raw

Re: [PATCH 3/4] MFD: Intel Out of Band Management Services Module (OOBMSM) driver

Quoted 73 lines · David E. Box

The Intel Out of Band Management Services Module (OOBMSM) is a device that provides access to Intel capabilities described in PCIE vendor specific extended capability registers (both VSEC and DVSEC). These capabilities include features like Intel Platform Monitoring Technology as well as others that are not supported by the intel_pmt driver. Add a driver for creating platform devices for these capabilities coming from OOBMSM.

---
 MAINTAINERS                  |  1 +
 drivers/mfd/Kconfig          | 11 +++++++
 drivers/mfd/Makefile         |  1 +
 drivers/mfd/intel_oobmsm.c   | 61 ++++++++++++++++++++++++++++++++++++
 drivers/platform/x86/Kconfig |  4 +--
 5 files changed, 76 insertions(+), 2 deletions(-)
 create mode 100644 drivers/mfd/intel_oobmsm.c
MAINTAINERS +1 -0
index ebdc2a0f794b..0961e3f89497 100644
@@ -9356,6 +9356,7 @@ INTEL PMT DRIVER
 M:	"David E. Box" <[email protected]>
 S:	Maintained
 F:	drivers/mfd/intel_extended_cap.c
+F:	drivers/mfd/intel_oobmsm.c
 F:	drivers/mfd/intel_pmt.c
 F:	drivers/platform/x86/intel_pmt_*
 
drivers/mfd/Kconfig +11 -0
index 4dde8e223a9e..269312de2666 100644
@@ -687,6 +687,17 @@ config MFD_INTEL_PMT
 	  Telemetry, Watcher, and Crashlog PMT capabilities/devices for
 	  platforms starting from Tiger Lake.
 
+config MFD_INTEL_OOBMSM
+	tristate "Intel Out Of Band Management Services Module (OOBMSM) support"
+	depends on PCI
+	select MFD_INTEL_EXTENDED_CAPS
+	help
+	  The Intel Out of Band Management Service Module driver is used to
+	  enumerate auxiliary platform features described in both Vendor
+	  Specific and Designated Vendor Specific PCIe config space. Supported
+	  features include Intel Platform Monitoring Technology (PMT) as well
+	  as other non-PMT capabilities.
+
 config MFD_IPAQ_MICRO
 	bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support"
 	depends on SA1100_H3100 || SA1100_H3600
drivers/mfd/Makefile +1 -0
index 7fa35399ec76..50fa38810bbd 100644
@@ -213,6 +213,7 @@ obj-$(CONFIG_MFD_INTEL_EXTENDED_CAPS)	+= intel_extended_caps.o
 obj-$(CONFIG_MFD_INTEL_LPSS)	+= intel-lpss.o
 obj-$(CONFIG_MFD_INTEL_LPSS_PCI)	+= intel-lpss-pci.o
 obj-$(CONFIG_MFD_INTEL_LPSS_ACPI)	+= intel-lpss-acpi.o
+obj-$(CONFIG_MFD_INTEL_OOBMSM)	+= intel_oobmsm.o
 obj-$(CONFIG_MFD_INTEL_PMC_BXT)	+= intel_pmc_bxt.o
 obj-$(CONFIG_MFD_INTEL_PMT)	+= intel_pmt.o
 obj-$(CONFIG_MFD_PALMAS)	+= palmas.o
drivers/mfd/intel_oobmsm.c new file +3 -0
new file mode 100644
index 000000000000..c66532f11c29
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Out of Band Management Services Module driver

drivers/mfd/intel_oobmsm.c line 13

Quoted 10 lines
drivers/mfd/intel_oobmsm.c new file +10 -0
+ *
+ * Copyright (c) 2021, Intel Corporation.
+ * All Rights Reserved.
+ *
+ * Author: David E. Box <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/pm_runtime.h>

This doesn't appear to have anything to do with MFD?

Quoted 69 lines
drivers/mfd/intel_oobmsm.c new file +47 -0
+#include "intel_extended_caps.h"
+
+static int intel_oobmsm_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct intel_ext_cap_platform_info *info;
+	int ret;
+
+	ret = pcim_enable_device(pdev);
+	if (ret)
+		return ret;
+
+	info = (struct intel_ext_cap_platform_info *)id->driver_data;
+
+	ret = intel_ext_cap_probe(pdev, info);
+	if (ret)
+		return ret;
+
+	pm_runtime_put(&pdev->dev);
+	pm_runtime_allow(&pdev->dev);
+
+	return 0;
+}
+
+static void intel_oobmsm_pci_remove(struct pci_dev *pdev)
+{
+	pm_runtime_forbid(&pdev->dev);
+	pm_runtime_get_sync(&pdev->dev);
+}
+
+#define PCI_DEVICE_ID_INTEL_PMT_OOBMSM	0x09a7
+static const struct pci_device_id intel_oobmsm_pci_ids[] = {
+	{ PCI_DEVICE_DATA(INTEL, PMT_OOBMSM, NULL) },
+	{ }
+};
+MODULE_DEVICE_TABLE(pci, intel_oobmsm_pci_ids);
+
+static struct pci_driver intel_oobmsm_pci_driver = {
+	.name = "intel-oobmsm",
+	.id_table = intel_oobmsm_pci_ids,
+	.probe = intel_oobmsm_pci_probe,
+	.remove = intel_oobmsm_pci_remove,
+};
+module_pci_driver(intel_oobmsm_pci_driver);
+
+MODULE_AUTHOR("David E. Box <[email protected]>");
+MODULE_DESCRIPTION("Intel Out of Band Management Services Module driver");
+MODULE_LICENSE("GPL v2");
drivers/platform/x86/Kconfig +2 -2
index 60592fb88e7a..4dd3af9f848e 100644
@@ -1226,7 +1226,7 @@ config INTEL_PMT_CLASS
 
 config INTEL_PMT_TELEMETRY
 	tristate "Intel Platform Monitoring Technology (PMT) Telemetry driver"
-	depends on MFD_INTEL_PMT
+	depends on MFD_INTEL_PMT || MFD_INTEL_OOBMSM
 	select INTEL_PMT_CLASS
 	help
 	  The Intel Platform Monitory Technology (PMT) Telemetry driver provides
@@ -1238,7 +1238,7 @@ config INTEL_PMT_TELEMETRY
 
 config INTEL_PMT_CRASHLOG
 	tristate "Intel Platform Monitoring Technology (PMT) Crashlog driver"
-	depends on MFD_INTEL_PMT
+	depends on MFD_INTEL_PMT || MFD_INTEL_OOBMSM
 	select INTEL_PMT_CLASS
 	help
 	  The Intel Platform Monitoring Technology (PMT) crashlog driver provides
Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#17 lore raw

PATCH 4/4 MFD: intel-extended-cap: Add support for PCIe VSEC structures

In reply to David E. Box

Adds support for discovering Intel extended capability features from Vendor Specific Extended Capability (VSEC) registers in PCIe config space. While doing so place the existing DVSEC and new VSEC code in separate functions.

---
 drivers/mfd/intel_extended_caps.c | 159 ++++++++++++++++++++----------
 1 file changed, 109 insertions(+), 50 deletions(-)
drivers/mfd/intel_extended_caps.c +109 -50
index 89cf1ae6f65b..9b60defda856 100644
@@ -105,7 +105,7 @@ static int intel_ext_cap_add_dev(struct pci_dev *pdev, struct intel_ext_cap_head
 		header->offset >>= 3;
 
 	/*
-	 * The DVSEC contains the starting offset and count for a block of
+	 * The DVSEC/VSEC contains the starting offset and count for a block of
 	 * discovery tables, each providing access to monitoring facilities for
 	 * a section of the device. Create a resource list of these tables to
 	 * provide to the driver.
@@ -124,11 +124,112 @@ static int intel_ext_cap_add_dev(struct pci_dev *pdev, struct intel_ext_cap_head
 	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, cell, 1, NULL, 0, NULL);
 }
 
+static bool intel_ext_cap_walk_dvsec(struct pci_dev *pdev, unsigned long quirks)
+{
+	int count = 0;
+	int pos = 0;
+
+	do {
+		struct intel_ext_cap_header header;
+		u32 table, hdr;
+		u16 vid;
+		int ret;
+
+		pos = pci_find_next_ext_capability(pdev, pos, PCI_EXT_CAP_ID_DVSEC);
+		if (!pos)
+			break;
+
+		pci_read_config_dword(pdev, pos + PCI_DVSEC_HEADER1, &hdr);
+		vid = PCI_DVSEC_HEADER1_VID(hdr);
+		if (vid != PCI_VENDOR_ID_INTEL)
+			continue;
+
+		/* Support only revision 1 */
+		header.rev = PCI_DVSEC_HEADER1_REV(hdr);
+		if (header.rev != 1) {
+			dev_warn(&pdev->dev, "Unsupported DVSEC revision %d\n",
+				 header.rev);
+			continue;
+		}
+
+		header.length = PCI_DVSEC_HEADER1_LEN(hdr);
+
+		pci_read_config_byte(pdev, pos + INTEL_DVSEC_ENTRIES,
+				     &header.num_entries);
+		pci_read_config_byte(pdev, pos + INTEL_DVSEC_SIZE,
+				     &header.entry_size);
+		pci_read_config_dword(pdev, pos + INTEL_DVSEC_TABLE,
+				      &table);
+
+		header.tbir = INTEL_DVSEC_TABLE_BAR(table);
+		header.offset = INTEL_DVSEC_TABLE_OFFSET(table);
+
+		pci_read_config_dword(pdev, pos + PCI_DVSEC_HEADER2, &hdr);
+		header.id = PCI_DVSEC_HEADER2_ID(hdr);
+
+		ret = intel_ext_cap_add_dev(pdev, &header, quirks);
+		if (ret)
+			continue;
+
+		count++;
+	} while (true);
+
+	return count;
+}
+
+static bool intel_ext_cap_walk_vsec(struct pci_dev *pdev, unsigned long quirks)
+{
+	int count = 0;
+	int pos = 0;
+
+	do {
+		struct intel_ext_cap_header header;
+		u32 table, hdr;
+		int ret;
+
+		pos = pci_find_next_ext_capability(pdev, pos, PCI_EXT_CAP_ID_VNDR);
+		if (!pos)
+			break;
+
+		pci_read_config_dword(pdev, pos + PCI_VNDR_HEADER, &hdr);
+
+		/* Support only revision 1 */
+		header.rev = PCI_VNDR_HEADER_REV(hdr);
+		if (header.rev != 1) {
+			dev_warn(&pdev->dev, "Unsupported VSEC revision %d\n",
+				 header.rev);
+			continue;
+		}
+
+		header.id = PCI_VNDR_HEADER_ID(hdr);
+		header.length = PCI_VNDR_HEADER_LEN(hdr);
+
+		/* entry, size, and table offset are the same as DVSEC */
+		pci_read_config_byte(pdev, pos + INTEL_DVSEC_ENTRIES,
+				     &header.num_entries);
+		pci_read_config_byte(pdev, pos + INTEL_DVSEC_SIZE,
+				     &header.entry_size);
+		pci_read_config_dword(pdev, pos + INTEL_DVSEC_TABLE,
+				      &table);
+
+		header.tbir = INTEL_DVSEC_TABLE_BAR(table);
+		header.offset = INTEL_DVSEC_TABLE_OFFSET(table);
+
+		ret = intel_ext_cap_add_dev(pdev, &header, quirks);
+		if (ret)
+			continue;
+
+		count++;
+	} while (true);
+
+	return count;
+}
+
 int intel_ext_cap_probe(struct pci_dev *pdev, struct intel_ext_cap_platform_info *info)
 {
 	unsigned long quirks = 0;
-	bool found_devices = false;
-	int ret, pos;
+	int device_count = 0;
+	int ret;
 
 	if (info)
 		quirks = info->quirks;
@@ -144,59 +245,17 @@ int intel_ext_cap_probe(struct pci_dev *pdev, struct intel_ext_cap_platform_info
 					 "Failed to add device for DVSEC id %d\n",
 					 (*header)->id);
 			else
-				found_devices = true;
+				device_count++;
 
 			header++;
 		}
-	} else {
-		/* Find DVSEC features */
-		pos = 0;
-		do {
-			struct intel_ext_cap_header header;
-			u32 table, hdr;
-			u16 vid;
-
-			pos = pci_find_next_ext_capability(pdev, pos, PCI_EXT_CAP_ID_DVSEC);
-			if (!pos)
-				break;
-
-			pci_read_config_dword(pdev, pos + PCI_DVSEC_HEADER1, &hdr);
-			vid = PCI_DVSEC_HEADER1_VID(hdr);
-			if (vid != PCI_VENDOR_ID_INTEL)
-				continue;
-
-			/* Support only revision 1 */
-			header.rev = PCI_DVSEC_HEADER1_REV(hdr);
-			if (header.rev != 1) {
-				dev_warn(&pdev->dev, "Unsupported DVSEC revision %d\n",
-					 header.rev);
-				continue;
-			}
-
-			header.length = PCI_DVSEC_HEADER1_LEN(hdr);
-
-			pci_read_config_byte(pdev, pos + INTEL_DVSEC_ENTRIES,
-					     &header.num_entries);
-			pci_read_config_byte(pdev, pos + INTEL_DVSEC_SIZE,
-					     &header.entry_size);
-			pci_read_config_dword(pdev, pos + INTEL_DVSEC_TABLE,
-					      &table);
-
-			header.tbir = INTEL_DVSEC_TABLE_BAR(table);
-			header.offset = INTEL_DVSEC_TABLE_OFFSET(table);
-
-			pci_read_config_dword(pdev, pos + PCI_DVSEC_HEADER2, &hdr);
-			header.id = PCI_DVSEC_HEADER2_ID(hdr);
-
-			ret = intel_ext_cap_add_dev(pdev, &header, quirks);
-			if (ret)
-				continue;
 
-			found_devices = true;
-		} while (true);
+	} else {
+		device_count += intel_ext_cap_walk_dvsec(pdev, quirks);
+		device_count += intel_ext_cap_walk_vsec(pdev, quirks);
 	}
 
-	if (!found_devices)
+	if (!device_count)
 		return -ENODEV;
 
 	return 0;
Signature · 1 line
2.25.1