Skip to contentSkip to conversation

Add command to set MPS of all PCI Express devices

PATCH Superseded [email protected] 2 participants 5 messages Mar 8, 2023 Char and misc drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add command to set MPS of all PCI Express devices

From: Stephen Carlson <[email protected]>

This patch set adds support for configuring the Maximum Payload Size (MPS) for attached PCI Express devices. Modifying the MPS can increase PCI Express performance or ensure compatibility with hot-plugged devices.

New config CONFIG_CMD_PCI_MPS. If enabled, a new "pci_mps" command will be added that accepts an argument describing a strategy to configure the PCI Express payload size for devices that are currently attached. Two strategies are currently supported:

"safe" emulates the Linux kernel's pci=pcie_bus_safe and sets all devices to the minimum MPS supported by all devices.

"peer2peer" sets all devices to an MPS of 128 bytes, the only size which must be supported by all compliant PCI Express devices, to ensure that all devices can directly communicate with each other and with devices that are hotplugged later.

A test for the sandbox environment is also added by advertising a larger supported Maximum Payload Size in the swapcase device and verifying that the pci_mps command can read and configure the MPS.

Stephen Carlson (3):
cmd: pci: Add command to set MPS of all PCIe devices
drivers: pci: sandbox: Add stub sandbox PCI MPS support
test: Add test for new command pci_mps

 MAINTAINERS                   |   6 ++
 cmd/Kconfig                   |  10 ++
 cmd/Makefile                  |   1 +
 cmd/pci_mps.c                 | 167 ++++++++++++++++++++++++++++++++++
 configs/sandbox_defconfig     |   1 +
 drivers/misc/swap_case.c      |   3 +
 include/pci.h                 |   7 ++
 test/py/tests/test_pci_mps.py |  13 +++
 8 files changed, 208 insertions(+)
 create mode 100644 cmd/pci_mps.c
 create mode 100644 test/py/tests/test_pci_mps.py
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 cmd: pci: Add command to set MPS of all PCIe devices

From: Stephen Carlson <[email protected]>

Enable tuning of the PCI Express MPS (Maximum Payload Size) of each device. The Maximum Read Request Size is not altered.

The SAFE method uses the largest MPS value supported by all devices in the system for each device. This method is the same algorithm as used by Linux pci=pcie_bus_safe.

The PEER2PEER method sets all devices to the minimal (128 byte) MPS, which allows hot plug of devices later that might only support the minimum size, and ensures compatibility of DMA between two devices on the bus.

---
 cmd/Kconfig   |  10 +++
 cmd/Makefile  |   1 +
 cmd/pci_mps.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/pci.h |   7 +++
 4 files changed, 185 insertions(+)
 create mode 100644 cmd/pci_mps.c
cmd/Kconfig +10 -0
index dc0446e02e..632c5c45db 100644
@@ -1390,6 +1390,16 @@ config CMD_PCI
 	  peripherals. Sub-commands allow bus enumeration, displaying and
 	  changing configuration space and a few other features.
 
+config CMD_PCI_MPS
+	bool "pci_mps - Configure PCI device MPS"
+	depends on PCI
+	help
+	  Enables PCI Express Maximum Packet Size (MPS) tuning. This
+	  command configures the PCI Express MPS of each endpoint to the
+	  largest value supported by all devices below the root complex.
+	  The Maximum Read Request Size will not be altered. This method is
+	  the same algorithm as used by Linux pci=pcie_bus_safe.
+
 config CMD_PINMUX
 	bool "pinmux - show pins muxing"
 	depends on PINCTRL
cmd/Makefile +1 -0
index 7b6ff73186..3365634843 100644
@@ -133,6 +133,7 @@ obj-$(CONFIG_CMD_PART) += part.o
 obj-$(CONFIG_CMD_PCAP) += pcap.o
 ifdef CONFIG_PCI
 obj-$(CONFIG_CMD_PCI) += pci.o
+obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o
 endif
 obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PMC) += pmc.o
cmd/pci_mps.c new file +167 -0

167 lines not on this page · raw message

include/pci.h +7 -0
index c55d6107a4..2f5eb30b83 100644
@@ -360,6 +360,13 @@
 #define   PCI_EXP_TYPE_PCIE_BRIDGE 0x8	/* PCI/PCI-X to PCIe Bridge */
 #define PCI_EXP_DEVCAP		4	/* Device capabilities */
 #define  PCI_EXP_DEVCAP_FLR	0x10000000 /* Function Level Reset */
+#define  PCI_EXP_DEVCAP_PAYLOAD 0x0007	/* Max payload size supported */
+#define  PCI_EXP_DEVCAP_PAYLOAD_128B 0x0000 /* 128 Bytes */
+#define  PCI_EXP_DEVCAP_PAYLOAD_256B 0x0001 /* 256 Bytes */
+#define  PCI_EXP_DEVCAP_PAYLOAD_512B 0x0002 /* 512 Bytes */
+#define  PCI_EXP_DEVCAP_PAYLOAD_1024B 0x0003 /* 1024 Bytes */
+#define  PCI_EXP_DEVCAP_PAYLOAD_2048B 0x0004 /* 2048 Bytes */
+#define  PCI_EXP_DEVCAP_PAYLOAD_4096B 0x0005 /* 4096 Bytes */
 #define PCI_EXP_DEVCTL		8	/* Device Control */
 #define  PCI_EXP_DEVCTL_PAYLOAD	0x00e0	/* Max_Payload_Size */
 #define  PCI_EXP_DEVCTL_PAYLOAD_128B 0x0000 /* 128 Bytes */
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/3 drivers: pci: sandbox: Add stub sandbox PCI MPS support

In reply to [email protected]

From: Stephen Carlson <[email protected]>

Reports the sandbox swapcase PCI Express device to support a 256 byte Maximum Payload Size for MPS tuning tests.

---
 drivers/misc/swap_case.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/misc/swap_case.c +3 -0
index 7093ad1cd4..ee5c12bd0a 100644
@@ -165,6 +165,9 @@ static int sandbox_swap_case_read_config(const struct udevice *emul,
 	case PCI_CAP_ID_EXP_OFFSET + PCI_CAP_LIST_NEXT:
 		*valuep = PCI_CAP_ID_MSIX_OFFSET;
 		break;
+	case PCI_CAP_ID_EXP_OFFSET + PCI_EXP_DEVCAP:
+		*valuep = PCI_EXP_DEVCAP_PAYLOAD_256B;
+		break;
 	case PCI_CAP_ID_MSIX_OFFSET:
 		if (sandbox_swap_case_use_ea(emul))
 			*valuep = (PCI_CAP_ID_EA_OFFSET << 8) | PCI_CAP_ID_MSIX;
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/3 test: Add test for new command pci_mps

In reply to [email protected]

From: Stephen Carlson <[email protected]>

Adds a test for the new pci_mps command to ensure that it can set the Maximum Payload Size (MPS) of all devices to 256 bytes in the sandbox environment. Enables the pci_mps command in the sandbox environment so that this test can be run.

---
 MAINTAINERS                   |  6 ++++++
 configs/sandbox_defconfig     |  1 +
 test/py/tests/test_pci_mps.py | 13 +++++++++++++
 3 files changed, 20 insertions(+)
 create mode 100644 test/py/tests/test_pci_mps.py
MAINTAINERS +6 -0
index 3e8e193ecc..83948b6aa7 100644
@@ -1242,6 +1242,12 @@ M:	Heiko Schocher <[email protected]>
 S:	Maintained
 F:	drivers/pci/pci_mpc85xx.c
 
+PCI MPS
+M:	Stephen Carlson <[email protected]>
+S:	Maintained
+F:	cmd/pci_mps.c
+F:	test/py/tests/test_pci_mps.py
+
 POWER
 M:	Jaehoon Chung <[email protected]>
 S:	Maintained
configs/sandbox_defconfig +1 -0
index 34c342b6f5..cd6bb8e2c4 100644
@@ -77,6 +77,7 @@ CONFIG_CMD_MMC=y
 CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
+CONFIG_CMD_PCI_MPS=y
 CONFIG_CMD_READ=y
 CONFIG_CMD_REMOTEPROC=y
 CONFIG_CMD_SPI=y
test/py/tests/test_pci_mps.py new file +13 -0
new file mode 100644
index 0000000000..8d33490f9f
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+import pytest
+
[email protected]('sandbox')
[email protected]('cmd_pci')
[email protected]('cmd_pci_mps')
+def test_pci_mps_safe(u_boot_console):
+    """Tests that PCI MPS can be set to safe mode and uses 256 bytes."""
+
+    response = u_boot_console.run_command('pci e; pci_mps s')
+    expected_response = 'to 256B'
+    assert(expected_response in response)
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 3/3] test: Add test for new command pci_mps

Hi Stephen,

Quoted 55 lines · On Tue, 7 Mar 2023 at 16:33, <[email protected]> wrote:

From: Stephen Carlson <[email protected]>

Adds a test for the new pci_mps command to ensure that it can set the Maximum Payload Size (MPS) of all devices to 256 bytes in the sandbox environment. Enables the pci_mps command in the sandbox environment so that this test can be run.

---
 MAINTAINERS                   |  6 ++++++
 configs/sandbox_defconfig     |  1 +
 test/py/tests/test_pci_mps.py | 13 +++++++++++++
 3 files changed, 20 insertions(+)
 create mode 100644 test/py/tests/test_pci_mps.py
MAINTAINERS +6 -0
index 3e8e193ecc..83948b6aa7 100644
@@ -1242,6 +1242,12 @@ M:       Heiko Schocher <[email protected]>
 S:     Maintained
 F:     drivers/pci/pci_mpc85xx.c
 
+PCI MPS
+M:     Stephen Carlson <[email protected]>
+S:     Maintained
+F:     cmd/pci_mps.c
+F:     test/py/tests/test_pci_mps.py
+
 POWER
 M:     Jaehoon Chung <[email protected]>
 S:     Maintained
configs/sandbox_defconfig +1 -0
index 34c342b6f5..cd6bb8e2c4 100644
@@ -77,6 +77,7 @@ CONFIG_CMD_MMC=y
 CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
+CONFIG_CMD_PCI_MPS=y
 CONFIG_CMD_READ=y
 CONFIG_CMD_REMOTEPROC=y
 CONFIG_CMD_SPI=y
test/py/tests/test_pci_mps.py new file +4 -0
new file mode 100644
index 0000000000..8d33490f9f
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+import pytest
+

test/py/tests/test_pci_mps.py

Quoted 10 lines
test/py/tests/test_pci_mps.py new file +9 -1
[email protected]('sandbox')
[email protected]('cmd_pci')
[email protected]('cmd_pci_mps')
+def test_pci_mps_safe(u_boot_console):
+    """Tests that PCI MPS can be set to safe mode and uses 256 bytes."""
+
+    response = u_boot_console.run_command('pci e; pci_mps s')
+    expected_response = 'to 256B'
+    assert(expected_response in response)
--

Can you please use C for this test? See [1]. For an example, see test/dm/acpi.c

Regards,
Simon

[1] https://u-boot.readthedocs.io/en/latest/develop/tests_writing.html#test-types