PCI: Enable 10-Bit tag support for PCIe devices
Subsystems (8)
v9 cover PCI: Enable 10-Bit tag support for PCIe devices
10-Bit Tag capability, introduced in PCIe-4.0 increases the total Tag field size from 8 bits to 10 bits.
This patchset is to enable 10-Bit tag for PCIe EP devices (include VF).
V8->V9:
- Rebased on V5.15-rc2.
- Rename pcie_devcap to devcap, pcie_devcap2 to devcap2 to keep the same style with commit 691392448065 ("PCI: Cache PCIe Device Capabilities register").
V7->V8:
- Add a kernel parameter pcie_tag_peer2peer to disable 10-bit tags.
- Provide sysfs file to enable 10-bit tags.
- Remove [PATCH V7 6/9] PCI: Enable 10-Bit Tag support for PCIe RP devices.
- Rebased on v5.14-rc6.
- Fix some other comments. Thanks to Bjorn who gave a lot of review comments.
V6->V7:
- Rebased on v5.14-rc3.
- Change the "pci=disable_10bit_tag=" parameter to sysfs file to disable 10-Bit Tag Requester when need for p2pdma suggested by Leon.
- Fix comment for p2pdma 10-bit tag check.
V5->V6:
- Rebased on v5.14-rc2.
- Add Reviewed-by: Christoph Hellwig <[email protected]> in [PATCH V6 2/8].
- PCI: Add "pci=disable_10bit_tag=" parameter for peer-to-peer support.
- Add a 10-bit tag check in P2PDMA.
- Simplified implementation in [PATCH V6 6/8].
- Fix some comments in [PATCH V6 4/8].
V4->V5:
- Fix warning variable 'capa' is uninitialized.
- Fix warning unused variable 'pchild'.
V3->V4:
- Get the value of pcie_devcap2 in set_pcie_port_type().
- Add Reviewed-by: Christoph Hellwig <[email protected]> in [PATCH V4 1/6], [PATCH V4 3/6], [PATCH V4 4/6], [PATCH V4 5/6].
- Fix some code style.
- Rebased on v5.13-rc6.
V2->V3:
- Use cached Device Capabilities Register suggested by Christoph.
- Fix code style to avoid > 80 char lines.
- Rename devcap2 to pcie_devcap2.
V1->V2: Fix some comments by Christoph.
- Store the devcap2 value in the pci_dev instead of reading it multiple times.
- Change pci_info to pci_dbg to avoid the noisy log.
- Rename ext_10bit_tag_comp_path to ext_10bit_tag.
- Fix the compile error.
- Rebased on v5.13-rc1.
Dongdong Liu (8):
PCI: Use cached devcap in more places
PCI: Cache Device Capabilities 2 Register
PCI: Add 10-Bit Tag register definitions PCI/sysfs: Add a 10-Bit Tag sysfs file PCIe Endpoint devices PCI/IOV: Add 10-Bit Tag sysfs files for VF devices PCI/P2PDMA: Add a 10-Bit Tag check in P2PDMA
PCI: Enable 10-Bit Tag support for PCIe Endpoint device PCI/IOV: Enable 10-Bit Tag support for PCIe VF devices
Documentation/ABI/testing/sysfs-bus-pci | 41 +++++++++- .../admin-guide/kernel-parameters.txt | 5 ++ drivers/media/pci/cobalt/cobalt-driver.c | 4 +- .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 +- drivers/pci/iov.c | 67 ++++++++++++++++ drivers/pci/p2pdma.c | 48 +++++++++++ drivers/pci/pci-sysfs.c | 79 +++++++++++++++++++ drivers/pci/pci.c | 12 +-- drivers/pci/pci.h | 9 +++ drivers/pci/pcie/aspm.c | 11 +-- drivers/pci/probe.c | 75 +++++++++++++++--- drivers/pci/quirks.c | 3 +- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 5 ++ 14 files changed, 332 insertions(+), 32 deletions(-)
--
2.22.0
PATCH v9 1/8 PCI: Use cached devcap in more places
Since commit 691392448065 ("PCI: Cache PCIe Device Capabilities register") has already added a new member called devcap in struct pci_dev for caching the PCIe Device Capabilities register to avoid reading PCI_EXP_DEVCAP multiple times. Use devcap in more needed places.
--- drivers/media/pci/cobalt/cobalt-driver.c | 4 ++-- drivers/pci/pcie/aspm.c | 11 ++++------- drivers/pci/probe.c | 7 +------ drivers/pci/quirks.c | 3 +-- 4 files changed, 8 insertions(+), 17 deletions(-)
drivers/media/pci/cobalt/cobalt-driver.c +2 -2
@@ -193,11 +193,11 @@ void cobalt_pcie_status_show(struct cobalt *cobalt)return ;/* Device */ -pcie_capability_read_dword (pci_dev,PCI_EXP_DEVCAP , &capa);pcie_capability_read_word (pci_dev,PCI_EXP_DEVCTL , &ctrl);pcie_capability_read_word (pci_dev,PCI_EXP_DEVSTA , &stat);cobalt_info ("PCIe device capability 0x%08x: Max payload %d\n" , - capa,get_payload_size (capa &PCI_EXP_DEVCAP_PAYLOAD )); + pci_dev->devcap, +get_payload_size (pci_dev->devcap &PCI_EXP_DEVCAP_PAYLOAD )); cobalt_info("PCIe device control 0x%04x: Max payload %d. Max read request %d\n", ctrl, get_payload_size((ctrl & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
drivers/pci/pcie/aspm.c +4 -7
@@ -660,7 +660,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)/* Get and check endpoint acceptable latencies */ list_for_each_entry (child, &linkbus->devices, bus_list) { -u32 reg32, encoding; +u32 encoding;struct aspm_latency *acceptable = &link->acceptable[PCI_FUNC (child->devfn)];
@@ -668,12 +668,11 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) pci_pcie_type(child) != PCI_EXP_TYPE_LEG_END)continue ; -pcie_capability_read_dword (child,PCI_EXP_DEVCAP , ®32);/* Calculate endpoint L0s acceptable latency */ - encoding = (reg32 &PCI_EXP_DEVCAP_L0S ) >>6 ; + encoding = (child->devcap &PCI_EXP_DEVCAP_L0S ) >>6 ; acceptable->l0s =calc_l0s_acceptable (encoding);/* Calculate endpoint L1 acceptable latency */ - encoding = (reg32 &PCI_EXP_DEVCAP_L1 ) >>9 ; + encoding = (child->devcap &PCI_EXP_DEVCAP_L1 ) >>9 ; acceptable->l1 =calc_l1_acceptable (encoding);pcie_aspm_check_latency (child);
@@ -808,7 +807,6 @@ static void free_link_state(struct pcie_link_state *link)static int pcie_aspm_sanity_check (struct pci_dev *pdev) {struct pci_dev *child; -u32 reg32;/* * Some functions in a slot might not all be PCIe functions,
@@ -831,8 +829,7 @@ static int pcie_aspm_sanity_check(struct pci_dev *pdev)* Disable ASPM for pre-1.1 PCIe device, we follow MS to use * RBER bit to determine if a function is 1.1 version device */ -pcie_capability_read_dword (child,PCI_EXP_DEVCAP , ®32); -if (!(reg32 &PCI_EXP_DEVCAP_RBER ) && !aspm_force) { +if (!(child->devcap &PCI_EXP_DEVCAP_RBER ) && !aspm_force) {pci_info (child,"disabling ASPM on pre-1.1 PCIe device. You can enable it with 'pcie_aspm=force'\n" );return -EINVAL ; }
drivers/pci/probe.c +1 -6
@@ -2044,18 +2044,13 @@ static void pci_configure_mps(struct pci_dev *dev)int pci_configure_extended_tags (struct pci_dev *dev,void *ign) {struct pci_host_bridge *host; -u32 cap;u16 ctl;int ret;if (!pci_is_pcie (dev))return 0 ; - ret =pcie_capability_read_dword (dev,PCI_EXP_DEVCAP , &cap); -if (ret) -return 0 ; - -if (!(cap &PCI_EXP_DEVCAP_EXT_TAG )) +if (!(dev->devcap &PCI_EXP_DEVCAP_EXT_TAG ))return 0 ; ret =pcie_capability_read_word (dev,PCI_EXP_DEVCTL , &ctl);
drivers/pci/quirks.c +1 -2
@@ -5260,8 +5260,7 @@ static void quirk_intel_qat_vf_cap(struct pci_dev *pdev) pdev->pcie_cap = pos;pci_read_config_word (pdev, pos +PCI_EXP_FLAGS , ®16); pdev->pcie_flags_reg = reg16; -pci_read_config_word (pdev, pos +PCI_EXP_DEVCAP , ®16); - pdev->pcie_mpss = reg16 &PCI_EXP_DEVCAP_PAYLOAD ; + pdev->pcie_mpss = pdev->devcap &PCI_EXP_DEVCAP_PAYLOAD ; pdev->cfg_size =PCI_CFG_SPACE_EXP_SIZE ; if (pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status) !=
Signature · 1 line
2.22.0
PATCH v9 2/8 PCI: Cache Device Capabilities 2 Register
In reply to Dongdong LiuAdd a new member called devcap2 in struct pci_dev for caching the PCIe Device Capabilities 2 register to avoid reading PCI_EXP_DEVCAP2 multiple times.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 +--- drivers/pci/pci.c | 8 +++----- drivers/pci/probe.c | 10 ++++------ include/linux/pci.h | 1 + 4 files changed, 9 insertions(+), 14 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +1 -3
@@ -6304,7 +6304,6 @@ static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)struct pci_dev *pbridge;struct port_info *pi;char name[IFNAMSIZ ]; -u32 devcap2;u16 flags;/* If we want to instantiate Virtual Functions, then our
@@ -6314,10 +6313,9 @@ static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)*/ pbridge = pdev->bus->self;pcie_capability_read_word (pbridge,PCI_EXP_FLAGS , &flags); -pcie_capability_read_dword (pbridge,PCI_EXP_DEVCAP2 , &devcap2);if ((flags &PCI_EXP_FLAGS_VERS ) <2 || - !(devcap2 &PCI_EXP_DEVCAP2_ARI )) { + !(pbridge->devcap2 &PCI_EXP_DEVCAP2_ARI )) {/* Our parent bridge does not support ARI so issue a * warning and skip instantiating the VFs. They * won't be reachable.
drivers/pci/pci.c +3 -5
@@ -3717,7 +3717,7 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask) {struct pci_bus *bus = dev->bus;struct pci_dev *bridge; -u32 cap, ctl2; +u32 ctl2;if (!pci_is_pcie (dev))return -EINVAL ;
@@ -3741,19 +3741,17 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)while (bus->parent) { bridge = bus->self; -pcie_capability_read_dword (bridge,PCI_EXP_DEVCAP2 , &cap); -switch (pci_pcie_type (bridge)) {/* Ensure switch ports support AtomicOp routing */ case PCI_EXP_TYPE_UPSTREAM :case PCI_EXP_TYPE_DOWNSTREAM : -if (!(cap &PCI_EXP_DEVCAP2_ATOMIC_ROUTE )) +if (!(bridge->devcap2 &PCI_EXP_DEVCAP2_ATOMIC_ROUTE ))return -EINVAL ;break ;/* Ensure root port supports all the sizes we care about */ case PCI_EXP_TYPE_ROOT_PORT : -if ((cap & cap_mask) != cap_mask) +if ((bridge->devcap2 & cap_mask) != cap_mask)return -EINVAL ;break ; }
drivers/pci/probe.c +4 -6
@@ -1509,6 +1509,7 @@ void set_pcie_port_type(struct pci_dev *pdev) pdev->pcie_flags_reg = reg16;pci_read_config_dword (pdev, pos +PCI_EXP_DEVCAP , &pdev->devcap); pdev->pcie_mpss =FIELD_GET (PCI_EXP_DEVCAP_PAYLOAD , pdev->devcap); +pci_read_config_dword (pdev, pos +PCI_EXP_DEVCAP2 , &pdev->devcap2); parent =pci_upstream_bridge (pdev);if (!parent)
@@ -2129,7 +2130,7 @@ static void pci_configure_ltr(struct pci_dev *dev)#ifdef CONFIG_PCIEASPM struct pci_host_bridge *host =pci_find_host_bridge (dev->bus);struct pci_dev *bridge; -u32 cap, ctl; +u32 ctl;if (!pci_is_pcie (dev))return ;
@@ -2137,8 +2138,7 @@ static void pci_configure_ltr(struct pci_dev *dev)/* Read L1 PM substate capabilities */ dev->l1ss =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_L1SS ); -pcie_capability_read_dword (dev,PCI_EXP_DEVCAP2 , &cap); -if (!(cap &PCI_EXP_DEVCAP2_LTR )) +if (!(dev->devcap2 &PCI_EXP_DEVCAP2_LTR ))return ;pcie_capability_read_dword (dev,PCI_EXP_DEVCTL2 , &ctl);
@@ -2178,13 +2178,11 @@ static void pci_configure_eetlp_prefix(struct pci_dev *dev)#ifdef CONFIG_PCI_PASID struct pci_dev *bridge;int pcie_type; -u32 cap;if (!pci_is_pcie (dev))return ; -pcie_capability_read_dword (dev,PCI_EXP_DEVCAP2 , &cap); -if (!(cap &PCI_EXP_DEVCAP2_EE_PREFIX )) +if (!(dev->devcap2 &PCI_EXP_DEVCAP2_EE_PREFIX ))return ; pcie_type =pci_pcie_type (dev);
include/linux/pci.h +1 -0
@@ -333,6 +333,7 @@ struct pci_dev {struct pci_dev *rcec;/* Associated RCEC device */ #endif u32 devcap;/* PCIe Device Capabilities */ +u32 devcap2;/* PCIe Device Capabilities 2 */ u8 pcie_cap;/* PCIe capability offset */ u8 msi_cap;/* MSI capability offset */ u8 msix_cap;/* MSI-X capability offset */
Signature · 1 line
2.22.0
PATCH v9 3/8 PCI: Add 10-Bit Tag register definitions
In reply to Dongdong LiuAdd 10-Bit Tag register definitions for use in subsequen patches. See the PCIe 5.0 spec section 7.5.3.15 and 9.3.3.2.
--- include/uapi/linux/pci_regs.h | 5 +++++ 1 file changed, 5 insertions(+)
include/uapi/linux/pci_regs.h +5 -0
@@ -648,6 +648,8 @@#define PCI_EXP_DEVCAP2_ATOMIC_COMP64 0x00000100/* 64b AtomicOp completion */ #define PCI_EXP_DEVCAP2_ATOMIC_COMP128 0x00000200/* 128b AtomicOp completion */ #define PCI_EXP_DEVCAP2_LTR 0x00000800/* Latency tolerance reporting */ +#define PCI_EXP_DEVCAP2_10BIT_TAG_COMP 0x00010000/* 10-Bit Tag Completer Supported */ +#define PCI_EXP_DEVCAP2_10BIT_TAG_REQ 0x00020000/* 10-Bit Tag Requester Supported */ #define PCI_EXP_DEVCAP2_OBFF_MASK 0x000c0000/* OBFF support mechanism */ #define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000/* New message signaling */ #define PCI_EXP_DEVCAP2_OBFF_WAKE 0x00080000/* Re-use WAKE# for OBFF */
@@ -661,6 +663,7 @@#define PCI_EXP_DEVCTL2_IDO_REQ_EN 0x0100/* Allow IDO for requests */ #define PCI_EXP_DEVCTL2_IDO_CMP_EN 0x0200/* Allow IDO for completions */ #define PCI_EXP_DEVCTL2_LTR_EN 0x0400/* Enable LTR mechanism */ +#define PCI_EXP_DEVCTL2_10BIT_TAG_REQ_EN 0x1000/* 10-Bit Tag Requester Enable */ #define PCI_EXP_DEVCTL2_OBFF_MSGA_EN 0x2000/* Enable OBFF Message type A */ #define PCI_EXP_DEVCTL2_OBFF_MSGB_EN 0x4000/* Enable OBFF Message type B */ #define PCI_EXP_DEVCTL2_OBFF_WAKE_EN 0x6000/* OBFF using WAKE# signaling */
@@ -931,6 +934,7 @@/* Single Root I/O Virtualization */ #define PCI_SRIOV_CAP 0x04/* SR-IOV Capabilities */ #define PCI_SRIOV_CAP_VFM 0x00000001/* VF Migration Capable */ +#define PCI_SRIOV_CAP_VF_10BIT_TAG_REQ 0x00000004/* VF 10-Bit Tag Requester Supported */ #define PCI_SRIOV_CAP_INTR (x) ((x) >> 21)/* Interrupt Message Number */ #define PCI_SRIOV_CTRL 0x08/* SR-IOV Control */ #define PCI_SRIOV_CTRL_VFE 0x0001/* VF Enable */
@@ -938,6 +942,7 @@#define PCI_SRIOV_CTRL_INTR 0x0004/* VF Migration Interrupt Enable */ #define PCI_SRIOV_CTRL_MSE 0x0008/* VF Memory Space Enable */ #define PCI_SRIOV_CTRL_ARI 0x0010/* ARI Capable Hierarchy */ +#define PCI_SRIOV_CTRL_VF_10BIT_TAG_REQ_EN 0x0020/* VF 10-Bit Tag Requester Enable */ #define PCI_SRIOV_STATUS 0x0a/* SR-IOV Status */ #define PCI_SRIOV_STATUS_VFM 0x0001/* VF Migration Status */ #define PCI_SRIOV_INITIAL_VF 0x0c/* Initial VFs */
Signature · 1 line
2.22.0
PATCH v9 4/8 PCI/sysfs: Add a 10-Bit Tag sysfs file PCIe Endpoint devices
In reply to Dongdong LiuPCIe spec 5.0 r1.0 section 2.2.6.2 says:
If an Endpoint supports sending Requests to other Endpoints (as opposed to host memory), the Endpoint must not send 10-Bit Tag Requests to another given Endpoint unless an implementation-specific mechanism determines that the Endpoint supports 10-Bit Tag Completer capability.
Add a 10bit_tag sysfs file, write 0 to disable 10-Bit Tag Requester when the driver does not bind the device. The typical use case is for p2pdma when the peer device does not support 10-Bit Tag Completer. Write 1 to enable 10-Bit Tag Requester when RC supports 10-Bit Tag Completer capability. The typical use case is for host memory targeted by DMA Requests. The 10bit_tag file content indicate current status of 10-Bit Tag Requester Enable.
--- Documentation/ABI/testing/sysfs-bus-pci | 18 +++++- drivers/pci/pci-sysfs.c | 76 +++++++++++++++++++++++++ drivers/pci/pci.h | 2 + drivers/pci/probe.c | 14 +++++ 4 files changed, 109 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-pci +17 -1
@@ -156,7 +156,7 @@ Description: binary file containing the Vital Product Data for the device. It should follow the VPD format defined in PCI Specification 2.1 or 2.2, but users should consider - that some devices may have incorrectly formatted data. + that some devices may have incorrectly formatted data. If the underlying VPD has a writable section then the corresponding section of this file will be writable.
@@ -424,3 +424,19 @@ Description: The file is writable if the PF is bound to a driver that implements ->sriov_set_msix_vec_count(). + +What: /sys/bus/pci/devices/.../10bit_tag +Date: September 2021 +Contact: Dongdong Liu <[email protected]> +Description: + The file will be visible when the device supports 10-Bit Tag + Requester. The file is readable, the value indicate current + status of 10-Bit Tag Requester Enable. + 1 - enabled, 0 - disabled. + + The file is also writable, write 0 to disable 10-Bit Tag + Requester when the driver does not bind the device. The typical + use case is for p2pdma when the peer device does not support + 10-Bit Tag Completer. Write 1 to enable 10-Bit Tag Requester + when RC supports 10-Bit Tag Completer capability. The typical + use case is for host memory targeted by DMA Requests.
drivers/pci/pci-sysfs.c +76 -0
106 lines not on this page · raw message
drivers/pci/pci.h +2 -0
@@ -264,6 +264,8 @@ struct device *pci_get_host_bridge_device(struct pci_dev *dev);void pci_put_host_bridge_device (struct device *dev);int pci_configure_extended_tags (struct pci_dev *dev,void *ign); +bool pcie_rp_10bit_tag_cmp_supported (struct pci_dev *dev); +bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *pl,int crs_timeout); bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
drivers/pci/probe.c +14 -0
@@ -2042,6 +2042,20 @@ static void pci_configure_mps(struct pci_dev *dev) p_mps, mps, mpss); } +bool pcie_rp_10bit_tag_cmp_supported (struct pci_dev *dev) +{ +struct pci_dev *root; + + root =pcie_find_root_port (dev); +if (!root) +return false; + +if (!(root->devcap2 &PCI_EXP_DEVCAP2_10BIT_TAG_COMP )) +return false; + +return true; +} +int pci_configure_extended_tags (struct pci_dev *dev,void *ign) {struct pci_host_bridge *host;
Signature · 1 line
2.22.0
Re: [PATCH V9 4/8] PCI/sysfs: Add a 10-Bit Tag sysfs file PCIe Endpoint devices
Hi,
Thank you for sending the patch over! A few small comments below.
[...]
drivers/pci/pci-sysfs.c static ssize_t enable_show(struct device *dev, struct device_attribute *attr, · line 314
Quoted 6 lines
drivers/pci/pci-sysfs.c +6
-0+static ssize_t pci_10bit_tag_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct pci_dev *pdev =to_pci_dev (dev); +bool enable;
Would you mind adding the following capabilities check here?
if (!capable(CAP_SYS_ADMIN)) return -EPERM;
This is so we make sure that whatever user is going to use this sysfs attribute actually has enough permissions to update this value safely.
drivers/pci/pci-sysfs.c static ssize_t enable_show(struct device *dev, struct device_attribute *attr, · line 324
Quoted 9 lines
drivers/pci/pci-sysfs.c +9
-0+if (kstrtobool (buf, &enable) <0 ) +return -EINVAL ; + +if (pdev->driver) +return -EBUSY ; + +if (enable) { +if (!pcie_rp_10bit_tag_cmp_supported (pdev)) +return -EPERM ;
Would it make sense to also verify 10-Bit Tag Completer support on the
"disable" path too? We won't be able to set a value if there is no
support, but nothing will stop us from clearing it regardless - unless this would be safe to do? What do you think?
Quoted 9 lines
drivers/pci/pci-sysfs.c +9
-0+pcie_capability_set_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_10BIT_TAG_REQ_EN ); + }else { +pcie_capability_clear_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_10BIT_TAG_REQ_EN ); + } + +return count; +}
[...]
drivers/pci/pci-sysfs.c static umode_t pcie_dev_attrs_are_visible(struct kobject *kobj, · line 1538
Quoted 2 lines
+> +static
umode_tpcie_dev_10bit_tag_attrs_are_visible(struct kobject *kobj,drivers/pci/pci-sysfs.c +1
-0+ struct attribute *a, int n)
The preferred function name for the .is_visible() callback in a case when there is only a single sysfs attribute being added would be:
pcie_dev_10bit_tag_attr_is_visible()
Albeit, I appreciate that you followed the existing naming pattern.
Krzysztof
Re: [PATCH V9 4/8] PCI/sysfs: Add a 10-Bit Tag sysfs file PCIe Endpoint devices
Hi Krzysztof
Many thanks for your review.
Quoted 5 lines · Krzysztof Wilczyński
Hi,
Thank you for sending the patch over! A few small comments below.
[...]
Quoted 8 lines
drivers/pci/pci-sysfs.c static ssize_t enable_show(struct device *dev, struct device_attribute *attr, · line 314
Quoted 6 lines
drivers/pci/pci-sysfs.c +6
-0+static ssize_t pci_10bit_tag_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct pci_dev *pdev =to_pci_dev (dev); +bool enable;Would you mind adding the following capabilities check here?
OK, will do.
Quoted 7 lines
if (!capable(CAP_SYS_ADMIN)) return -EPERM;This is so we make sure that whatever user is going to use this sysfs attribute actually has enough permissions to update this value safely.
Quoted 14 lines
drivers/pci/pci-sysfs.c static ssize_t enable_show(struct device *dev, struct device_attribute *attr, · line 324
Quoted 9 lines
drivers/pci/pci-sysfs.c +9
-0+if (kstrtobool (buf, &enable) <0 ) +return -EINVAL ; + +if (pdev->driver) +return -EBUSY ; + +if (enable) { +if (!pcie_rp_10bit_tag_cmp_supported (pdev)) +return -EPERM ;Would it make sense to also verify 10-Bit Tag Completer support on the
"disable" path too? We won't be able to set a value if there is no
support, but nothing will stop us from clearing it regardless - unless this would be safe to do? What do you think?
Seems make sense, Will do. It is better do the same thing on the "disable" path too.
Quoted 12 lines
Quoted 10 lines
drivers/pci/pci-sysfs.c +9
-0+pcie_capability_set_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_10BIT_TAG_REQ_EN ); + }else { +pcie_capability_clear_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_10BIT_TAG_REQ_EN ); + } + +return count; +}[...]
Quoted 7 lines
drivers/pci/pci-sysfs.c static umode_t pcie_dev_attrs_are_visible(struct kobject *kobj, · line 1538
Quoted 2 lines
+> +static
umode_tpcie_dev_10bit_tag_attrs_are_visible(struct kobject *kobj,drivers/pci/pci-sysfs.c +1
-0+ struct attribute *a, int n)The preferred function name for the .is_visible() callback in a case when there is only a single sysfs attribute being added would be:
pcie_dev_10bit_tag_attr_is_visible()
Will fix.
Thanks,
Dongdong
Quoted 6 lines
Albeit, I appreciate that you followed the existing naming pattern.
Krzysztof
.
PATCH v9 5/8 PCI/IOV: Add 10-Bit Tag sysfs files for VF devices
In reply to Dongdong LiuPCIe spec 5.0 r1.0 section 2.2.6.2 says:
If an Endpoint supports sending Requests to other Endpoints (as opposed to host memory), the Endpoint must not send 10-Bit Tag Requests to another given Endpoint unless an implementation-specific mechanism determines that the Endpoint supports 10-Bit Tag Completer capability.
Add sriov_vf_10bit_tag file to query the status of VF 10-Bit Tag Requester Enable.
Add a sriov_vf_10bit_tag_ctl sysfs file, write 0 to disable the VF 10-Bit Tag Requester. The typical use case is for p2pdma when the peer device does not support 10-Bit Tag Completer. Write 1 to enable 10-Bit Tag Requester when RC supports 10-Bit Tag Completer capability. The typical use case is for host memory targeted by DMA Requests.
--- Documentation/ABI/testing/sysfs-bus-pci | 23 +++++++++++ drivers/pci/iov.c | 53 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
Documentation/ABI/testing/sysfs-bus-pci +23 -0
@@ -440,3 +440,26 @@ Description: 10-Bit Tag Completer. Write 1 to enable 10-Bit Tag Requester when RC supports 10-Bit Tag Completer capability. The typical use case is for host memory targeted by DMA Requests. + +What: /sys/bus/pci/devices/.../sriov_vf_10bit_tag +Date: September 2021 +Contact: Dongdong Liu <[email protected]> +Description: + This file is associated with a SR-IOV physical function (PF). + It is visible when the device supports VF 10-Bit Tag Requester. + It contains the status of VF 10-Bit Tag Requester Enable. + The file is read-only. + +What: /sys/bus/pci/devices/.../sriov_vf_10bit_tag_ctl +Date: September 2021 +Contact: Dongdong Liu <[email protected]> +Description: + This file is associated with a SR-IOV virtual function (VF). + It is visible when the device supports VF 10-Bit Tag + Requester. The file is only writeable when the VF driver + does not bind to a device. Write 0 to any VF's file disables + 10-Bit Tag Requester for all VFs. The typical use case is for + p2pdma when the peer device does not support 10-Bit Tag + Completer. Write 1 to enable 10-Bit Tag Requester for all VFs + when RC supports 10-Bit Tag Completer capability. The typical + use case is for host memory targeted by DMA Requests.
drivers/pci/iov.c +53 -0
97 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH v9 6/8 PCI/P2PDMA: Add a 10-Bit Tag check in P2PDMA
In reply to Dongdong LiuAdd a 10-Bit Tag check in the P2PDMA code to ensure that a device with 10-Bit Tag Requester doesn't interact with a device that does not support 10-Bit Tag Completer. Before that happens, the kernel should emit a warning.
"echo 0 > /sys/bus/pci/devices/.../10bit_tag" to disable 10-Bit Tag Requester for PF device.
"echo 0 > /sys/bus/pci/devices/.../sriov_vf_10bit_tag_ctl" to disable 10-Bit Tag Requester for VF device.
--- drivers/pci/p2pdma.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
drivers/pci/p2pdma.c +48 -0
@@ -19,6 +19,7 @@#include <linux/random.h> #include <linux/seq_buf.h> #include <linux/xarray.h> +#include "pci.h" enum pci_p2pdma_map_type {PCI_P2PDMA_MAP_UNKNOWN =0 ,
@@ -410,6 +411,50 @@ static unsigned long map_types_idx(struct pci_dev *client) (client->bus->number <<8 ) | client->devfn; } +static bool pci_10bit_tags_unsupported (struct pci_dev *a, +struct pci_dev *b, +bool verbose) +{ +bool req; +bool comp; +u16 ctl; +const char *str ="10bit_tag" ; + +if (a->is_virtfn) { +#ifdef CONFIG_PCI_IOV + req = !!(a->physfn->sriov->ctrl & +PCI_SRIOV_CTRL_VF_10BIT_TAG_REQ_EN ); +#endif + }else { +pcie_capability_read_word (a,PCI_EXP_DEVCTL2 , &ctl); + req = !!(ctl &PCI_EXP_DEVCTL2_10BIT_TAG_REQ_EN ); + } + + comp = !!(b->devcap2 &PCI_EXP_DEVCAP2_10BIT_TAG_COMP ); + +/* 10-bit tags not enabled on requester */ +if (!req) +return false; + +/* Completer can handle anything */ +if (comp) +return false; + +if (!verbose) +return true; + +pci_warn (a,"cannot be used for peer-to-peer DMA as 10-Bit Tag Requester enable is set for this device, but peer device (%s) does not support the 10-Bit Tag Completer\n" , +pci_name (b)); + +if (a->is_virtfn) + str ="sriov_vf_10bit_tag_ctl" ; + +pci_warn (a,"to disable 10-Bit Tag Requester for this device, echo 0 > /sys/bus/pci/devices/%s/%s\n" , +pci_name (a), str); + +return true; +} +/* * Calculate the P2PDMA mapping type and distance between two PCI devices. *
@@ -532,6 +577,9 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client, map_type =PCI_P2PDMA_MAP_NOT_SUPPORTED ; } done: +if (pci_10bit_tags_unsupported (client, provider, verbose)) + map_type =PCI_P2PDMA_MAP_NOT_SUPPORTED ; +rcu_read_lock (); p2pdma =rcu_dereference (provider->p2pdma);if (p2pdma)
Signature · 1 line
2.22.0
PATCH v9 7/8 PCI: Enable 10-Bit Tag support for PCIe Endpoint device
In reply to Dongdong Liu10-Bit Tag capability, introduced in PCIe-4.0 increases the total Tag field size from 8 bits to 10 bits.
PCIe spec 5.0 r1.0 section 2.2.6.2 "Considerations for Implementing 10-Bit Tag Capabilities" Implementation Note:
For platforms where the RC supports 10-Bit Tag Completer capability, it is highly recommended for platform firmware or operating software that configures PCIe hierarchies to Set the 10-Bit Tag Requester Enable bit automatically in Endpoints with 10-Bit Tag Requester capability. This enables the important class of 10-Bit Tag capable adapters that send Memory Read Requests only to host memory.
It's safe to enable 10-bit tags for all devices below a Root Port that supports them. Switches that lack 10-Bit Tag Completer capability are still able to forward NPRs and Completions carrying 10-Bit Tags correctly, since the two new Tag bits are in TLP Header bits that were formerly Reserved.
PCIe spec 5.0 r1.0 section 2.2.6.2 says:
If an Endpoint supports sending Requests to other Endpoints (as opposed to host memory), the Endpoint must not send 10-Bit Tag Requests to another given Endpoint unless an implementation-specific mechanism determines that the Endpoint supports 10-Bit Tag Completer capability.
It is not safe for P2P traffic if an Endpoint send 10-Bit Tag Requesters to another Endpoint that does not support 10-Bit Tag Completer capability, so we provide sysfs file to disable 10-Bit Tag Requester. Unbind the device driver, set the sysfs file and then rebind the driver.
Add a kernel parameter pcie_tag_peer2peer that disables 10-Bit Tag Requester for all PCIe devices. This configuration allows peer-to-peer DMA between any pair of devices, possibly at the cost of reduced performance.
--- .../admin-guide/kernel-parameters.txt | 5 ++ drivers/pci/iov.c | 3 ++ drivers/pci/pci-sysfs.c | 3 ++ drivers/pci/pci.c | 4 ++ drivers/pci/pci.h | 7 +++ drivers/pci/probe.c | 46 ++++++++++++++++++- 6 files changed, 67 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -3979,6 +3979,11 @@ any pair of devices, possibly at the cost of reduced performance. This also guarantees that hot-added devices will work. + pcie_tag_peer2peer Disable 10-Bit Tag Requester for all + PCIe devices. This configuration allows + peer-to-peer DMA between any pair of devices, + possibly at the cost of reduced performance. + cbiosize=nn[KMG] The fixed amount of bus space which is reserved for the CardBus bridge's IO window. The default value is 256 bytes.
drivers/pci/iov.c +3 -0
@@ -234,6 +234,9 @@ static ssize_t sriov_vf_10bit_tag_ctl_store(struct device *dev,if (vf_dev->driver)return -EBUSY ; +if (pcie_tag_config ==PCIE_TAG_PEER2PEER ) +return -EPERM ; +if (enable) {if (!pcie_rp_10bit_tag_cmp_supported (pdev))return -EPERM ;
drivers/pci/pci-sysfs.c +3 -0
@@ -319,6 +319,9 @@ static ssize_t pci_10bit_tag_store(struct device *dev,if (pdev->driver)return -EBUSY ; +if (pcie_tag_config ==PCIE_TAG_PEER2PEER ) +return -EPERM ; +if (enable) {if (!pcie_rp_10bit_tag_cmp_supported (pdev))return -EPERM ;
drivers/pci/pci.c +4 -0
@@ -118,6 +118,8 @@ enum pcie_bus_config_types pcie_bus_config = PCIE_BUS_PEER2PEER;enum pcie_bus_config_types pcie_bus_config =PCIE_BUS_DEFAULT ;#endif +enum pcie_tag_config_types pcie_tag_config =PCIE_TAG_DEFAULT ; +/* * The default CLS is used if arch didn't set CLS explicitly and not * all pci devices agree on the same value. Arch can override either
@@ -6795,6 +6797,8 @@ static int __init pci_setup(char *str)pci_add_flags (PCI_SCAN_ALL_PCIE_DEVS ); }else if (!strncmp (str,"disable_acs_redir=" ,18 )) { disable_acs_redir_param = str +18 ; + }else if (!strncmp (str,"pcie_tag_peer2peer" ,18 )) { + pcie_tag_config =PCIE_TAG_PEER2PEER ; }else {pr_err ("PCI: Unknown option `%s'\n" , str); }
drivers/pci/pci.h +7 -0
@@ -59,6 +59,13 @@ struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);struct pci_cap_saved_state *pci_find_saved_ext_cap (struct pci_dev *dev,u16 cap); +enum pcie_tag_config_types { +PCIE_TAG_DEFAULT ,/* Enable 10-Bit Tag Requester for devices below +Root Port that support 10-Bit Tag Completer. */ +PCIE_TAG_PEER2PEER /* Disable 10-Bit Tag Requester for all devices. */ +}; +extern enum pcie_tag_config_types pcie_tag_config; +#define PCI_PM_D2_DELAY 200/* usec; see PCIe r4.0, sec 5.9.1 */ #define PCI_PM_D3HOT_WAIT 10/* msec */ #define PCI_PM_D3COLD_WAIT 100/* msec */
drivers/pci/probe.c +45 -1
73 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH v9 8/8 PCI/IOV: Enable 10-Bit Tag support for PCIe VF devices
In reply to Dongdong LiuEnable 10-Bit Tag Requester for the VF devices below the Root Port that support 10-Bit Tag Completer.
--- drivers/pci/iov.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/pci/iov.c +11 -0
@@ -690,6 +690,15 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)pci_iov_set_numvfs (dev, nr_virtfn); iov->ctrl |=PCI_SRIOV_CTRL_VFE |PCI_SRIOV_CTRL_MSE ; + +if ((pcie_tag_config ==PCIE_TAG_DEFAULT ) && + (iov->cap &PCI_SRIOV_CAP_VF_10BIT_TAG_REQ ) && +pcie_rp_10bit_tag_cmp_supported (dev)) + iov->ctrl |=PCI_SRIOV_CTRL_VF_10BIT_TAG_REQ_EN ; + +if (pcie_tag_config ==PCIE_TAG_PEER2PEER ) + iov->ctrl &= ~PCI_SRIOV_CTRL_VF_10BIT_TAG_REQ_EN ; +pci_cfg_access_lock (dev);pci_write_config_word (dev, iov->pos +PCI_SRIOV_CTRL , iov->ctrl);msleep (100 );
@@ -706,6 +715,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) err_pcibios: iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE |PCI_SRIOV_CTRL_MSE ); + iov->ctrl &= ~PCI_SRIOV_CTRL_VF_10BIT_TAG_REQ_EN ;pci_cfg_access_lock (dev);pci_write_config_word (dev, iov->pos +PCI_SRIOV_CTRL , iov->ctrl);ssleep (1 );
@@ -738,6 +748,7 @@ static void sriov_disable(struct pci_dev *dev)sriov_del_vfs (dev); iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE |PCI_SRIOV_CTRL_MSE ); + iov->ctrl &= ~PCI_SRIOV_CTRL_VF_10BIT_TAG_REQ_EN ;pci_cfg_access_lock (dev);pci_write_config_word (dev, iov->pos +PCI_SRIOV_CTRL , iov->ctrl);ssleep (1 );
Signature · 1 line
2.22.0