Expose and manage PCI device reset
Subsystems (6)
v8 cover Expose and manage PCI device reset
PCI and PCIe devices may support a number of possible reset mechanisms for example Function Level Reset (FLR) provided via Advanced Feature or PCIe capabilities, Power Management reset, bus reset, or device specific reset. Currently the PCI subsystem creates a policy prioritizing these reset methods which provides neither visibility nor control to userspace.
Expose the reset methods available per device to userspace, via sysfs and allow an administrative user or device owner to have ability to manage per device reset method priorities or exclusions. This feature aims to allow greater control of a device for use cases as device assignment, where specific device or platform issues may interact poorly with a given reset method, and for which device specific quirks have not been developed.
Changes in v8:
- Added has_flr bitfield to struct pci_dev to cache flr capability
- Updated encoding scheme used in reset_methods array as per Bjorn's suggestion
- Updated Shanker's ACPI patches
Changes in v7:
- Fix the pci_dev_acpi_reset() prototype mismatch in case of CONFIG_ACPI=n
Changes in v6:
- Address Bjorn's and Krzysztof's review comments
- Add Shanker's updated patches along with new "PCI: Setup ACPI_COMPANION early" patch
Changes in v5:
- Rebase the series over pci/reset branch of Bjorn's pci tree to avoid merge conflicts caused by recent changes in existing reset sysfs attribute
Changes in v4:
- Change the order or strlen and strim in reset_method_store function to avoid extra strlen call.
- Use consistent terminology in new pci_reset_mode enum and rename the probe argument of reset functions.
Changes in v3:
- Dropped "PCI: merge slot and bus reset implementations" which was already accepted separately
- Grammar fixes
- Added Shanker's patches which were rebased on v2 of this series
- Added "PCI: Change the type of probe argument in reset functions" and additional user input sanitization code in reset_method_store function per review feedback from Krzysztof
Changes in v2:
- Use byte array instead of bitmap to keep track of ordering of reset methods
- Fix incorrect use of reset_fn field in octeon driver
- Allow writing comma separated list of names of supported reset methods to reset_method sysfs attribute
- Writing empty string instead of "none" to reset_method attribute disables ability of reset the device
Amey Narkhede (5):
PCI: Add pcie_reset_flr to follow calling convention of other reset
methods
PCI: Add new array for keeping track of ordering of reset methods
PCI: Remove reset_fn field from pci_dev
PCI/sysfs: Allow userspace to query and set device reset mechanism
PCI: Change the type of probe argument in reset functions
Shanker Donthineni (3):
PCI: Define a function to set ACPI_COMPANION in pci_dev
PCI: Setup ACPI fwnode early and at the same time with OF
PCI: Add support for ACPI _RST reset method
Documentation/ABI/testing/sysfs-bus-pci | 19 ++ drivers/crypto/cavium/nitrox/nitrox_main.c | 4 +- .../ethernet/cavium/liquidio/lio_vf_main.c | 2 +- drivers/pci/hotplug/pciehp.h | 2 +- drivers/pci/hotplug/pciehp_hpc.c | 4 +- drivers/pci/pci-acpi.c | 38 ++- drivers/pci/pci-sysfs.c | 106 ++++++++- drivers/pci/pci.c | 222 ++++++++++-------- drivers/pci/pci.h | 23 +- drivers/pci/pcie/aer.c | 12 +- drivers/pci/probe.c | 17 +- drivers/pci/quirks.c | 44 ++-- drivers/pci/remove.c | 1 - include/linux/pci.h | 21 +- include/linux/pci_hotplug.h | 2 +- 15 files changed, 366 insertions(+), 151 deletions(-)
--
2.32.0
PATCH v8 1/8 PCI: Add pcie_reset_flr to follow calling convention of other reset methods
Add has_flr bitfield in struct pci_dev to indicate support for pcie flr to avoid reading PCI_EXP_DEVCAP multiple times and get rid of PCI_DEV_FLAGS_NO_FLR_RESET in quirk_no_flr().
Currently there is separate function pcie_has_flr() to probe if pcie flr is supported by the device which does not match the calling convention followed by reset methods which use second function argument to decide whether to probe or not. Add new function pcie_reset_flr() that follows the calling convention of reset methods.
--- drivers/crypto/cavium/nitrox/nitrox_main.c | 4 +- drivers/pci/pci.c | 62 +++++++++++----------- drivers/pci/pcie/aer.c | 12 ++--- drivers/pci/probe.c | 6 ++- drivers/pci/quirks.c | 11 ++-- include/linux/pci.h | 7 ++- 6 files changed, 47 insertions(+), 55 deletions(-)
drivers/crypto/cavium/nitrox/nitrox_main.c +1 -3
@@ -306,9 +306,7 @@ static int nitrox_device_flr(struct pci_dev *pdev)return -ENOMEM ; } -/* check flr support */ -if (pcie_has_flr (pdev)) -pcie_flr (pdev); +pcie_reset_flr (pdev,0 );pci_restore_state (pdev);
drivers/pci/pci.c +30 -32
97 lines not on this page · raw message
drivers/pci/pcie/aer.c +5 -7
@@ -1405,13 +1405,11 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) }if (type ==PCI_EXP_TYPE_RC_EC || type ==PCI_EXP_TYPE_RC_END ) { -if (pcie_has_flr (dev)) { - rc =pcie_flr (dev); -pci_info (dev,"has been reset (%d)\n" , rc); - }else { -pci_info (dev,"not reset (no FLR support)\n" ); - rc = -ENOTTY ; - } + rc =pcie_reset_flr (dev,0 ); +if (!rc) +pci_info (dev,"has been reset\n" ); +else +pci_info (dev,"not reset (no FLR support: %d)\n" , rc); }else { rc =pci_bus_error_reset (dev); pci_info(dev, "%s Port link has been reset (%d)\n",
drivers/pci/probe.c +4 -2
@@ -1487,6 +1487,7 @@ void set_pcie_port_type(struct pci_dev *pdev) {int pos;u16 reg16; +u32 reg32;int type;struct pci_dev *parent;
@@ -1497,8 +1498,9 @@ void set_pcie_port_type(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 ; +pci_read_config_dword (pdev, pos +PCI_EXP_DEVCAP , ®32); + pdev->pcie_mpss = reg32 &PCI_EXP_DEVCAP_PAYLOAD ; + pdev->has_flr = reg32 &PCI_EXP_DEVCAP_FLR ?1 :0 ; parent =pci_upstream_bridge (pdev);if (!parent)
drivers/pci/quirks.c +4 -7
@@ -3819,7 +3819,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)u32 cfg;if (dev->class !=PCI_CLASS_STORAGE_EXPRESS || - !pcie_has_flr (dev) || !pci_resource_start (dev,0 )) +pcie_reset_flr (dev,1 ) || !pci_resource_start (dev,0 ))return -ENOTTY ;if (probe)
@@ -3888,13 +3888,10 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)*/ static int delay_250ms_after_flr (struct pci_dev *dev,int probe) { -if (!pcie_has_flr (dev)) -return -ENOTTY ; +int ret =pcie_reset_flr (dev, probe);if (probe) -return 0 ; - -pcie_flr (dev); +return ret;msleep (250 );
@@ -5182,7 +5179,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x443, quirk_intel_qat_vf_cap);*/ static void quirk_no_flr (struct pci_dev *dev) { - dev->dev_flags |=PCI_DEV_FLAGS_NO_FLR_RESET ; + dev->has_flr =0 ; }DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_AMD ,0x1487 , quirk_no_flr);DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_AMD ,0x148c , quirk_no_flr);
include/linux/pci.h +3 -4
@@ -223,10 +223,8 @@ enum pci_dev_flags {PCI_DEV_FLAGS_VPD_REF_F0 = (__force pci_dev_flags_t) (1 <<8 ),/* A non-root bridge where translation occurs, stop alias search here */ PCI_DEV_FLAGS_BRIDGE_XLATE_ROOT = (__force pci_dev_flags_t) (1 <<9 ), -/* Do not use FLR even if device advertises PCI_AF_CAP */ -PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 <<10 ),/* Don't use Relaxed Ordering for TLPs directed at this device */ - PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 11), + PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 10), }; enum pci_irq_reroute_variant {
@@ -381,6 +379,7 @@ struct pci_dev {bit manually */ unsigned int d3hot_delay;/* D3hot->D0 transition time in ms */ unsigned int d3cold_delay;/* D3cold->D0 transition time in ms */ + unsigned int has_flr:1;#ifdef CONFIG_PCIEASPM struct pcie_link_state *link_state;/* ASPM link state */
@@ -1225,7 +1224,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,enum pci_bus_speed *speed, enum pcie_link_width *width);void pcie_print_link_status (struct pci_dev *dev); -bool pcie_has_flr (struct pci_dev *dev); +int pcie_reset_flr (struct pci_dev *dev,int probe);int pcie_flr (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);
Signature · 1 line
2.32.0
Re: [PATCH v8 1/8] PCI: Add pcie_reset_flr to follow calling convention of other reset methods
Quoted 4 lines · On Tue, 29 Jun 2021 21:30:57 +0530 Amey Narkhede <[email protected]>…
Add
has_flrbitfield in structpci_devto indicate support for pcie flr to avoid readingPCI_EXP_DEVCAPmultiple times and get rid ofPCI_DEV_FLAGS_NO_FLR_RESETinquirk_no_flr().
Quoted 8 lines
Currently there is separate function
pcie_has_flr()to probe if pcie flr is supported by the device which does not match the calling convention followed by reset methods which use second function argument to decide whether to probe or not. Add new functionpcie_reset_flr()that follows the calling convention of reset methods.Co-developed-by Alex Williamson <[email protected]>Signed-off-by Alex Williamson <[email protected]>
There are some non-trivial changes here vs previous, should probably drop this.
Quoted 93 lines
Signed-off-by Amey Narkhede <[email protected]>--- drivers/crypto/cavium/nitrox/nitrox_main.c | 4 +- drivers/pci/pci.c | 62 +++++++++++----------- drivers/pci/pcie/aer.c | 12 ++--- drivers/pci/probe.c | 6 ++- drivers/pci/quirks.c | 11 ++-- include/linux/pci.h | 7 ++- 6 files changed, 47 insertions(+), 55 deletions(-)drivers/crypto/cavium/nitrox/nitrox_main.c +1
-3@@ -306,9 +306,7 @@ static int nitrox_device_flr(struct pci_dev *pdev)return -ENOMEM ; } -/* check flr support */ -if (pcie_has_flr (pdev)) -pcie_flr (pdev); +pcie_reset_flr (pdev,0 );pci_restore_state (pdev);drivers/pci/pci.c +21
-23@@ -4611,32 +4611,12 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) }EXPORT_SYMBOL (pci_wait_for_pending_transaction); -/** -* pcie_has_flr - check if a device supports function level resets -* @dev: device to check -* -* Returns true if the device advertises support for PCIe function level -* resets. -*/ -bool pcie_has_flr (struct pci_dev *dev) -{ -u32 cap; - -if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET ) -return false; - -pcie_capability_read_dword (dev,PCI_EXP_DEVCAP , &cap); -return cap &PCI_EXP_DEVCAP_FLR ; -} -EXPORT_SYMBOL_GPL (pcie_has_flr); -/** * pcie_flr - initiate a PCIe function level reset * @dev: device to reset * -* Initiate a function level reset on @dev. The caller should ensure the -* device supports FLR before calling this function, e.g. by using the -* pcie_has_flr() helper. +* Initiate a function level reset unconditionally on @dev without +* checking any flags and DEVCAP */ int pcie_flr (struct pci_dev *dev) {@@ -4659,16 +4639,35 @@ int pcie_flr(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pcie_flr); +/** +* pcie_reset_flr - initiate a PCIe function level reset +* @dev: device to reset +* @probe: If set, only check if the device can be reset this way. +* +* Initiate a function level reset on @dev. +*/ +int pcie_reset_flr (struct pci_dev *dev,int probe) +{ +if (!dev->has_flr) +return -ENOTTY ; + +if (probe) +return 0 ; + +return pcie_flr (dev); +} +EXPORT_SYMBOL_GPL (pcie_reset_flr); +static int pci_af_flr (struct pci_dev *dev,int probe) {int pos;u8 cap; - pos =pci_find_capability (dev,PCI_CAP_ID_AF );
drivers/pci/pci.c int pcie_flr(struct pci_dev *dev) · line 4673
Quoted 10 lines
drivers/pci/pci.c +3
-2-if (!pos) +if (!dev->has_flr)return -ENOTTY ; -if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET ) + pos =pci_find_capability (dev,PCI_CAP_ID_AF ); +if (!pos)return -ENOTTY ;pci_read_config_byte (dev, pos +PCI_AF_CAP , &cap);
How can has_flr encompass both methods of invoking FLR? PCIe FLR is not a prerequisite to AF FLR.
Quoted 63 lines
drivers/pci/pci.c +6
-7@@ -5139,11 +5138,9 @@ int __pci_reset_function_locked(struct pci_dev *dev) rc =pci_dev_specific_reset (dev,0 );if (rc != -ENOTTY )return rc; -if (pcie_has_flr (dev)) { - rc =pcie_flr (dev); -if (rc != -ENOTTY ) -return rc; - } + rc =pcie_reset_flr (dev,0 ); +if (rc != -ENOTTY ) +return rc; rc =pci_af_flr (dev,0 );if (rc != -ENOTTY )return rc;@@ -5174,8 +5171,9 @@ int pci_probe_reset_function(struct pci_dev *dev) rc =pci_dev_specific_reset (dev,1 );if (rc != -ENOTTY )return rc; -if (pcie_has_flr (dev)) -return 0 ; + rc =pcie_reset_flr (dev,1 ); +if (rc != -ENOTTY ) +return rc; rc =pci_af_flr (dev,1 );if (rc != -ENOTTY )return rc;drivers/pci/pcie/aer.c +5
-7@@ -1405,13 +1405,11 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) }if (type ==PCI_EXP_TYPE_RC_EC || type ==PCI_EXP_TYPE_RC_END ) { -if (pcie_has_flr (dev)) { - rc =pcie_flr (dev); -pci_info (dev,"has been reset (%d)\n" , rc); - }else { -pci_info (dev,"not reset (no FLR support)\n" ); - rc = -ENOTTY ; - } + rc =pcie_reset_flr (dev,0 ); +if (!rc) +pci_info (dev,"has been reset\n" ); +else +pci_info (dev,"not reset (no FLR support: %d)\n" , rc); }else { rc =pci_bus_error_reset (dev); pci_info(dev, "%s Port link has been reset (%d)\n",drivers/pci/probe.c +1
-0@@ -1487,6 +1487,7 @@ void set_pcie_port_type(struct pci_dev *pdev) {int pos;u16 reg16; +u32 reg32;int type;struct pci_dev *parent;
drivers/pci/probe.c void set_pcie_port_type(struct pci_dev *pdev) · line 1503
Quoted 8 lines
drivers/pci/probe.c +3
-2@@ -1497,8 +1498,9 @@ void set_pcie_port_type(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 ; +pci_read_config_dword (pdev, pos +PCI_EXP_DEVCAP , ®32); + pdev->pcie_mpss = reg32 &PCI_EXP_DEVCAP_PAYLOAD ; + pdev->has_flr = reg32 &PCI_EXP_DEVCAP_FLR ?1 :0 ;
We only set has_flr for PCIe FLR, so I think this effectively kills AF FLR. The ternary should be unnecessary here.
Quoted 58 lines
drivers/pci/probe.c +0
-0parent =pci_upstream_bridge (pdev);if (!parent)drivers/pci/quirks.c +4
-7@@ -3819,7 +3819,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)u32 cfg;if (dev->class !=PCI_CLASS_STORAGE_EXPRESS || - !pcie_has_flr (dev) || !pci_resource_start (dev,0 )) +pcie_reset_flr (dev,1 ) || !pci_resource_start (dev,0 ))return -ENOTTY ;if (probe)@@ -3888,13 +3888,10 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)*/ static int delay_250ms_after_flr (struct pci_dev *dev,int probe) { -if (!pcie_has_flr (dev)) -return -ENOTTY ; +int ret =pcie_reset_flr (dev, probe);if (probe) -return 0 ; - -pcie_flr (dev); +return ret;msleep (250 );@@ -5182,7 +5179,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x443, quirk_intel_qat_vf_cap);*/ static void quirk_no_flr (struct pci_dev *dev) { - dev->dev_flags |=PCI_DEV_FLAGS_NO_FLR_RESET ; + dev->has_flr =0 ; }DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_AMD ,0x1487 , quirk_no_flr);DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_AMD ,0x148c , quirk_no_flr);include/linux/pci.h +1
-3@@ -223,10 +223,8 @@ enum pci_dev_flags {PCI_DEV_FLAGS_VPD_REF_F0 = (__force pci_dev_flags_t) (1 <<8 ),/* A non-root bridge where translation occurs, stop alias search here */ PCI_DEV_FLAGS_BRIDGE_XLATE_ROOT = (__force pci_dev_flags_t) (1 <<9 ), -/* Do not use FLR even if device advertises PCI_AF_CAP */ -PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 <<10 ),/* Don't use Relaxed Ordering for TLPs directed at this device */ - PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 11), + PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 10), }; enum pci_irq_reroute_variant {
include/linux/pci.h struct pci_dev { · line 382
Quoted 4 lines
include/linux/pci.h +1
-0@@ -381,6 +379,7 @@ struct pci_dev {bit manually */ unsigned int d3hot_delay;/* D3hot->D0 transition time in ms */ unsigned int d3cold_delay;/* D3cold->D0 transition time in ms */ + unsigned int has_flr:1;
There are more space efficient places to define this. Thanks,
Alex
Quoted 12 lines
include/linux/pci.h +1
-1#ifdef CONFIG_PCIEASPM struct pcie_link_state *link_state;/* ASPM link state */ @@ -1225,7 +1224,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,enum pci_bus_speed *speed, enum pcie_link_width *width);void pcie_print_link_status (struct pci_dev *dev); -bool pcie_has_flr (struct pci_dev *dev); +int pcie_reset_flr (struct pci_dev *dev,int probe);int pcie_flr (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);
Re: [PATCH v8 1/8] PCI: Add pcie_reset_flr to follow calling convention of other reset methods
Quoted 121 lines · Alex Williamson
Quoted 4 lines · On Tue, 29 Jun 2021 21:30:57 +0530 Amey Narkhede <[email protected]>…
Add
has_flrbitfield in structpci_devto indicate support for pcie flr to avoid readingPCI_EXP_DEVCAPmultiple times and get rid ofPCI_DEV_FLAGS_NO_FLR_RESETinquirk_no_flr().Quoted 8 lines
Currently there is separate function
pcie_has_flr()to probe if pcie flr is supported by the device which does not match the calling convention followed by reset methods which use second function argument to decide whether to probe or not. Add new functionpcie_reset_flr()that follows the calling convention of reset methods.Co-developed-by Alex Williamson <[email protected]>Signed-off-by Alex Williamson <[email protected]>There are some non-trivial changes here vs previous, should probably drop this.
Quoted 102 lines
Signed-off-by Amey Narkhede <[email protected]>--- drivers/crypto/cavium/nitrox/nitrox_main.c | 4 +- drivers/pci/pci.c | 62 +++++++++++----------- drivers/pci/pcie/aer.c | 12 ++--- drivers/pci/probe.c | 6 ++- drivers/pci/quirks.c | 11 ++-- include/linux/pci.h | 7 ++- 6 files changed, 47 insertions(+), 55 deletions(-)drivers/crypto/cavium/nitrox/nitrox_main.c +1
-3@@ -306,9 +306,7 @@ static int nitrox_device_flr(struct pci_dev *pdev)return -ENOMEM ; } -/* check flr support */ -if (pcie_has_flr (pdev)) -pcie_flr (pdev); +pcie_reset_flr (pdev,0 );pci_restore_state (pdev);drivers/pci/pci.c +24
-25@@ -4611,32 +4611,12 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) }EXPORT_SYMBOL (pci_wait_for_pending_transaction); -/** -* pcie_has_flr - check if a device supports function level resets -* @dev: device to check -* -* Returns true if the device advertises support for PCIe function level -* resets. -*/ -bool pcie_has_flr (struct pci_dev *dev) -{ -u32 cap; - -if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET ) -return false; - -pcie_capability_read_dword (dev,PCI_EXP_DEVCAP , &cap); -return cap &PCI_EXP_DEVCAP_FLR ; -} -EXPORT_SYMBOL_GPL (pcie_has_flr); -/** * pcie_flr - initiate a PCIe function level reset * @dev: device to reset * -* Initiate a function level reset on @dev. The caller should ensure the -* device supports FLR before calling this function, e.g. by using the -* pcie_has_flr() helper. +* Initiate a function level reset unconditionally on @dev without +* checking any flags and DEVCAP */ int pcie_flr (struct pci_dev *dev) {@@ -4659,16 +4639,35 @@ int pcie_flr(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pcie_flr); +/** +* pcie_reset_flr - initiate a PCIe function level reset +* @dev: device to reset +* @probe: If set, only check if the device can be reset this way. +* +* Initiate a function level reset on @dev. +*/ +int pcie_reset_flr (struct pci_dev *dev,int probe) +{ +if (!dev->has_flr) +return -ENOTTY ; + +if (probe) +return 0 ; + +return pcie_flr (dev); +} +EXPORT_SYMBOL_GPL (pcie_reset_flr); +static int pci_af_flr (struct pci_dev *dev,int probe) {int pos;u8 cap; - pos =pci_find_capability (dev,PCI_CAP_ID_AF ); -if (!pos) +if (!dev->has_flr)return -ENOTTY ; -if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET ) + pos =pci_find_capability (dev,PCI_CAP_ID_AF ); +if (!pos)return -ENOTTY ;
Quoted 6 lines
drivers/pci/pci.c int pcie_flr(struct pci_dev *dev) · line 4673
Quoted 1 line
drivers/pci/pci.c +0
-0pci_read_config_byte (dev, pos +PCI_AF_CAP , &cap);How can
has_flrencompass both methods of invoking FLR? PCIe FLR is not a prerequisite to AF FLR.
I see. Does this mean that there should be a separate flag for disabling AF FLR?
Quoted 63 lines
Quoted 63 lines
drivers/pci/pci.c +6
-7@@ -5139,11 +5138,9 @@ int __pci_reset_function_locked(struct pci_dev *dev) rc =pci_dev_specific_reset (dev,0 );if (rc != -ENOTTY )return rc; -if (pcie_has_flr (dev)) { - rc =pcie_flr (dev); -if (rc != -ENOTTY ) -return rc; - } + rc =pcie_reset_flr (dev,0 ); +if (rc != -ENOTTY ) +return rc; rc =pci_af_flr (dev,0 );if (rc != -ENOTTY )return rc;@@ -5174,8 +5171,9 @@ int pci_probe_reset_function(struct pci_dev *dev) rc =pci_dev_specific_reset (dev,1 );if (rc != -ENOTTY )return rc; -if (pcie_has_flr (dev)) -return 0 ; + rc =pcie_reset_flr (dev,1 ); +if (rc != -ENOTTY ) +return rc; rc =pci_af_flr (dev,1 );if (rc != -ENOTTY )return rc;drivers/pci/pcie/aer.c +5
-7@@ -1405,13 +1405,11 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) }if (type ==PCI_EXP_TYPE_RC_EC || type ==PCI_EXP_TYPE_RC_END ) { -if (pcie_has_flr (dev)) { - rc =pcie_flr (dev); -pci_info (dev,"has been reset (%d)\n" , rc); - }else { -pci_info (dev,"not reset (no FLR support)\n" ); - rc = -ENOTTY ; - } + rc =pcie_reset_flr (dev,0 ); +if (!rc) +pci_info (dev,"has been reset\n" ); +else +pci_info (dev,"not reset (no FLR support: %d)\n" , rc); }else { rc =pci_bus_error_reset (dev); pci_info(dev, "%s Port link has been reset (%d)\n",drivers/pci/probe.c +1
-0@@ -1487,6 +1487,7 @@ void set_pcie_port_type(struct pci_dev *pdev) {int pos;u16 reg16; +u32 reg32;int type;struct pci_dev *parent;
Quoted 13 lines
drivers/pci/probe.c void set_pcie_port_type(struct pci_dev *pdev) · line 1503
Quoted 9 lines
drivers/pci/probe.c +3
-2@@ -1497,8 +1498,9 @@ void set_pcie_port_type(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 ; +pci_read_config_dword (pdev, pos +PCI_EXP_DEVCAP , ®32); + pdev->pcie_mpss = reg32 &PCI_EXP_DEVCAP_PAYLOAD ; + pdev->has_flr = reg32 &PCI_EXP_DEVCAP_FLR ?1 :0 ;We only set
has_flrfor PCIe FLR, so I think this effectively kills AF FLR. The ternary should be unnecessary here.
I believe only one of the PCIe FLR and PCI AF FLR will be available at a time. So I think it should be okay to check for PCI_AF_CAP_FLR and set pdev->has_flr accordingly. One question though, what is PCI_AF_CAP_TP and how is it related to PCI AF FLR?
Quoted 65 lines
Quoted 58 lines
drivers/pci/probe.c +0
-0parent =pci_upstream_bridge (pdev);if (!parent)drivers/pci/quirks.c +4
-7@@ -3819,7 +3819,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)u32 cfg;if (dev->class !=PCI_CLASS_STORAGE_EXPRESS || - !pcie_has_flr (dev) || !pci_resource_start (dev,0 )) +pcie_reset_flr (dev,1 ) || !pci_resource_start (dev,0 ))return -ENOTTY ;if (probe)@@ -3888,13 +3888,10 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)*/ static int delay_250ms_after_flr (struct pci_dev *dev,int probe) { -if (!pcie_has_flr (dev)) -return -ENOTTY ; +int ret =pcie_reset_flr (dev, probe);if (probe) -return 0 ; - -pcie_flr (dev); +return ret;msleep (250 );@@ -5182,7 +5179,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x443, quirk_intel_qat_vf_cap);*/ static void quirk_no_flr (struct pci_dev *dev) { - dev->dev_flags |=PCI_DEV_FLAGS_NO_FLR_RESET ; + dev->has_flr =0 ; }DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_AMD ,0x1487 , quirk_no_flr);DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_AMD ,0x148c , quirk_no_flr);include/linux/pci.h +1
-3@@ -223,10 +223,8 @@ enum pci_dev_flags {PCI_DEV_FLAGS_VPD_REF_F0 = (__force pci_dev_flags_t) (1 <<8 ),/* A non-root bridge where translation occurs, stop alias search here */ PCI_DEV_FLAGS_BRIDGE_XLATE_ROOT = (__force pci_dev_flags_t) (1 <<9 ), -/* Do not use FLR even if device advertises PCI_AF_CAP */ -PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 <<10 ),/* Don't use Relaxed Ordering for TLPs directed at this device */ - PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 11), + PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 10), }; enum pci_irq_reroute_variant {include/linux/pci.h struct pci_dev { · line 382
Quoted 4 lines
include/linux/pci.h +1
-0@@ -381,6 +379,7 @@ struct pci_dev {bit manually */ unsigned int d3hot_delay;/* D3hot->D0 transition time in ms */ unsigned int d3cold_delay;/* D3cold->D0 transition time in ms */ + unsigned int has_flr:1;There are more space efficient places to define this. Thanks,
Quoted 2 lines
Alex
Oops. Will update this in v9.
Thanks,
Amey
Quoted 13 lines
Quoted 12 lines
include/linux/pci.h +1
-1#ifdef CONFIG_PCIEASPM struct pcie_link_state *link_state;/* ASPM link state */ @@ -1225,7 +1224,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,enum pci_bus_speed *speed, enum pcie_link_width *width);void pcie_print_link_status (struct pci_dev *dev); -bool pcie_has_flr (struct pci_dev *dev); +int pcie_reset_flr (struct pci_dev *dev,int probe);int pcie_flr (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);
Re: [PATCH v8 1/8] PCI: Add pcie_reset_flr to follow calling convention of other reset methods
Quoted 122 lines · On Thu, 1 Jul 2021 01:34:15 +0530 Amey Narkhede <[email protected]>…
Quoted 121 lines · Alex Williamson
Quoted 4 lines · On Tue, 29 Jun 2021 21:30:57 +0530 Amey Narkhede <[email protected]>…
Add
has_flrbitfield in structpci_devto indicate support for pcie flr to avoid readingPCI_EXP_DEVCAPmultiple times and get rid ofPCI_DEV_FLAGS_NO_FLR_RESETinquirk_no_flr().Quoted 8 lines
Currently there is separate function
pcie_has_flr()to probe if pcie flr is supported by the device which does not match the calling convention followed by reset methods which use second function argument to decide whether to probe or not. Add new functionpcie_reset_flr()that follows the calling convention of reset methods.Co-developed-by Alex Williamson <[email protected]>Signed-off-by Alex Williamson <[email protected]>There are some non-trivial changes here vs previous, should probably drop this.
Quoted 102 lines
Signed-off-by Amey Narkhede <[email protected]>--- drivers/crypto/cavium/nitrox/nitrox_main.c | 4 +- drivers/pci/pci.c | 62 +++++++++++----------- drivers/pci/pcie/aer.c | 12 ++--- drivers/pci/probe.c | 6 ++- drivers/pci/quirks.c | 11 ++-- include/linux/pci.h | 7 ++- 6 files changed, 47 insertions(+), 55 deletions(-)drivers/crypto/cavium/nitrox/nitrox_main.c +1
-3@@ -306,9 +306,7 @@ static int nitrox_device_flr(struct pci_dev *pdev)return -ENOMEM ; } -/* check flr support */ -if (pcie_has_flr (pdev)) -pcie_flr (pdev); +pcie_reset_flr (pdev,0 );pci_restore_state (pdev);drivers/pci/pci.c +24
-25@@ -4611,32 +4611,12 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) }EXPORT_SYMBOL (pci_wait_for_pending_transaction); -/** -* pcie_has_flr - check if a device supports function level resets -* @dev: device to check -* -* Returns true if the device advertises support for PCIe function level -* resets. -*/ -bool pcie_has_flr (struct pci_dev *dev) -{ -u32 cap; - -if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET ) -return false; - -pcie_capability_read_dword (dev,PCI_EXP_DEVCAP , &cap); -return cap &PCI_EXP_DEVCAP_FLR ; -} -EXPORT_SYMBOL_GPL (pcie_has_flr); -/** * pcie_flr - initiate a PCIe function level reset * @dev: device to reset * -* Initiate a function level reset on @dev. The caller should ensure the -* device supports FLR before calling this function, e.g. by using the -* pcie_has_flr() helper. +* Initiate a function level reset unconditionally on @dev without +* checking any flags and DEVCAP */ int pcie_flr (struct pci_dev *dev) {@@ -4659,16 +4639,35 @@ int pcie_flr(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pcie_flr); +/** +* pcie_reset_flr - initiate a PCIe function level reset +* @dev: device to reset +* @probe: If set, only check if the device can be reset this way. +* +* Initiate a function level reset on @dev. +*/ +int pcie_reset_flr (struct pci_dev *dev,int probe) +{ +if (!dev->has_flr) +return -ENOTTY ; + +if (probe) +return 0 ; + +return pcie_flr (dev); +} +EXPORT_SYMBOL_GPL (pcie_reset_flr); +static int pci_af_flr (struct pci_dev *dev,int probe) {int pos;u8 cap; - pos =pci_find_capability (dev,PCI_CAP_ID_AF ); -if (!pos) +if (!dev->has_flr)return -ENOTTY ; -if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET ) + pos =pci_find_capability (dev,PCI_CAP_ID_AF ); +if (!pos)return -ENOTTY ;
Quoted 8 lines
Quoted 6 lines
drivers/pci/pci.c int pcie_flr(struct pci_dev *dev) · line 4673
Quoted 1 line
drivers/pci/pci.c +0
-0pci_read_config_byte (dev, pos +PCI_AF_CAP , &cap);How can
has_flrencompass both methods of invoking FLR? PCIe FLR is not a prerequisite to AF FLR.I see. Does this mean that there should be a separate flag for disabling AF FLR?
There hasn't been a need so far. Per the ECN, the AF capability is meant to make select PCIe features available on conventional PCI devices. It seems like it would be against the spirit of the AF capability to implement both an AF capability and a PCIe capability, but I don't see that it's definitively addressed by the spec.
AF FLR is sufficiently rare that it's probably reasonable to make a has_pcie_flr bit on the device and leave AF FLR alone. I can't really say that I'm in favor of assigning a has_flr bit the double duty of also quirking broken FLR, if nothing else it's inconsistent with our other means of quirking resets.
Quoted 75 lines
Quoted 62 lines
Quoted 62 lines
drivers/pci/pci.c +6
-7@@ -5139,11 +5138,9 @@ int __pci_reset_function_locked(struct pci_dev *dev) rc =pci_dev_specific_reset (dev,0 );if (rc != -ENOTTY )return rc; -if (pcie_has_flr (dev)) { - rc =pcie_flr (dev); -if (rc != -ENOTTY ) -return rc; - } + rc =pcie_reset_flr (dev,0 ); +if (rc != -ENOTTY ) +return rc; rc =pci_af_flr (dev,0 );if (rc != -ENOTTY )return rc;@@ -5174,8 +5171,9 @@ int pci_probe_reset_function(struct pci_dev *dev) rc =pci_dev_specific_reset (dev,1 );if (rc != -ENOTTY )return rc; -if (pcie_has_flr (dev)) -return 0 ; + rc =pcie_reset_flr (dev,1 ); +if (rc != -ENOTTY ) +return rc; rc =pci_af_flr (dev,1 );if (rc != -ENOTTY )return rc;drivers/pci/pcie/aer.c +5
-7@@ -1405,13 +1405,11 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) }if (type ==PCI_EXP_TYPE_RC_EC || type ==PCI_EXP_TYPE_RC_END ) { -if (pcie_has_flr (dev)) { - rc =pcie_flr (dev); -pci_info (dev,"has been reset (%d)\n" , rc); - }else { -pci_info (dev,"not reset (no FLR support)\n" ); - rc = -ENOTTY ; - } + rc =pcie_reset_flr (dev,0 ); +if (!rc) +pci_info (dev,"has been reset\n" ); +else +pci_info (dev,"not reset (no FLR support: %d)\n" , rc); }else { rc =pci_bus_error_reset (dev); pci_info(dev, "%s Port link has been reset (%d)\n",drivers/pci/probe.c +1
-0@@ -1487,6 +1487,7 @@ void set_pcie_port_type(struct pci_dev *pdev) {int pos;u16 reg16; +u32 reg32;int type;struct pci_dev *parent;Quoted 13 lines
drivers/pci/probe.c void set_pcie_port_type(struct pci_dev *pdev) · line 1503
Quoted 9 lines
drivers/pci/probe.c +3
-2@@ -1497,8 +1498,9 @@ void set_pcie_port_type(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 ; +pci_read_config_dword (pdev, pos +PCI_EXP_DEVCAP , ®32); + pdev->pcie_mpss = reg32 &PCI_EXP_DEVCAP_PAYLOAD ; + pdev->has_flr = reg32 &PCI_EXP_DEVCAP_FLR ?1 :0 ;We only set
has_flrfor PCIe FLR, so I think this effectively kills AF FLR. The ternary should be unnecessary here.
Quoted 1 line
I believe only one of the PCIe FLR and PCI AF FLR will be available at a time.
Likely, possibly required depending on spec interpretation.
Quoted 2 lines
So I think it should be okay to check for
PCI_AF_CAP_FLRand setpdev->has_flraccordingly.
AF FLR is rare, are the reasons we're wanting to cache its availability as relevant as they are for PCIe FLR?
Quoted 1 line
One question though, what is
PCI_AF_CAP_TP
Transaction Pending
Quoted 1 line
and how is it related to PCI AF FLR?
It's required to be implemented if AF FLR is implemented. We're supposed to wait for TP to clear before issuing an FLR to avoid an issue with stale completions of outstanding transactions. Thanks,
Alex
Re: [PATCH v8 1/8] PCI: Add pcie_reset_flr to follow calling convention of other reset methods
Please add "()" after function names in subject lines.
Quoted 10 lines · Alex Williamson
Quoted 8 lines · On Thu, 1 Jul 2021 01:34:15 +0530 Amey Narkhede <[email protected]>…
Quoted 7 lines · Alex Williamson
Quoted 4 lines · On Tue, 29 Jun 2021 21:30:57 +0530 Amey Narkhede <[email protected]>…
Add
has_flrbitfield in structpci_devto indicate support for pcie flr to avoid readingPCI_EXP_DEVCAPmultiple times and get rid ofPCI_DEV_FLAGS_NO_FLR_RESETinquirk_no_flr().
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Currently there is separate function
pcie_has_flr()to probe if pcie flr is supported by the device which does not match the calling convention followed by reset methods which use second function argument to decide whether to probe or not. Add new functionpcie_reset_flr()that follows the calling convention of reset methods.
s/pcie/PCIe/ (except for variables, function names, etc)
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
static int
pci_af_flr(struct pci_dev *dev, int probe){drivers/pci/pci.c +3
-3int pos;u8 cap; - pos =pci_find_capability (dev,PCI_CAP_ID_AF ); -if (!pos) +if (!dev->has_flr)return -ENOTTY ; -if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET ) + pos =pci_find_capability (dev,PCI_CAP_ID_AF ); +if (!pos)return -ENOTTY ;Quoted 8 lines
Quoted 6 lines
Quoted 1 line
pci_read_config_byte(dev, pos + PCI_AF_CAP, &cap);How can
has_flrencompass both methods of invoking FLR? PCIe FLR is not a prerequisite to AF FLR.I see. Does this mean that there should be a separate flag for disabling AF FLR?
Quoted 8 lines
There hasn't been a need so far. Per the ECN, the AF capability is meant to make select PCIe features available on conventional PCI devices. It seems like it would be against the spirit of the AF capability to implement both an AF capability and a PCIe capability, but I don't see that it's definitively addressed by the spec.
AF FLR is sufficiently rare that it's probably reasonable to make a
has_pcie_flrbit on the device and leave AF FLR alone.
This sounds good to me. I agree that I'd prefer not to have a single bit that applies to both AF FLR and PCIe FLR since they are distinct mechanisms, discovered and initiated differently.
Quoted 3 lines
I can't really say that I'm in favor of assigning a
has_flrbit the double duty of also quirking broken FLR, if nothing else it's inconsistent with our other means of quirking resets.
By "other means of quirking resets," do you mean PCI_DEV_FLAGS_NO_BUS_RESET, PCI_DEV_FLAGS_NO_PM_RESET, and PCI_DEV_FLAGS_NO_FLR_RESET?
I agree that a pdev->has_pcie_flr bit would be different from those, and maybe it's better to stick with PCI_DEV_FLAGS_NO_FLR_RESET for now.
In general, I don't like the dual approach of some things being in the pci_dev_flags enum and others being "unsigned int foo:1" in the struct pci_dev because I can't tell if there's a reason to choose one over the other. If there's not a reason to have both, I'd like to migrate them all to the ":1" approach because it seems a little more readable to me.
Bjorn
PATCH v8 2/8 PCI: Add new array for keeping track of ordering of reset methods
In reply to Amey NarkhedeIntroduce a new array reset_methods in struct pci_dev to keep track of reset mechanisms supported by the device and their ordering.
Also refactor probing and reset functions to take advantage of calling convention of reset functions.
--- drivers/pci/pci.c | 97 ++++++++++++++++++++++++++------------------- drivers/pci/pci.h | 9 ++++- drivers/pci/probe.c | 5 +-- include/linux/pci.h | 7 ++++ 4 files changed, 74 insertions(+), 44 deletions(-)
drivers/pci/pci.c +57 -40
@@ -72,6 +72,14 @@ static void pci_dev_d3_sleep(struct pci_dev *dev)msleep (delay); } +int pci_reset_supported (struct pci_dev *dev) +{ +u8 null_reset_methods[PCI_NUM_RESET_METHODS ] = {0 }; + +return memcmp (null_reset_methods, + dev->reset_methods,sizeof (null_reset_methods)); +} +#ifdef CONFIG_PCI_DOMAINS int pci_domains_supported =1 ;#endif
@@ -5101,6 +5109,19 @@ static void pci_dev_restore(struct pci_dev *dev) err_handler->reset_done (dev); } +/* +* The ordering for functions in pci_reset_fn_methods is required for +* reset_methods byte array defined in struct pci_dev. +*/ +const struct pci_reset_fn_method pci_reset_fn_methods[] = { + { }, + { &pci_dev_specific_reset, .name ="device_specific" }, + { &pcie_reset_flr, .name ="flr" }, + { &pci_af_flr, .name ="af_flr" }, + { &pci_pm_reset, .name ="pm" }, + { &pci_reset_bus_function, .name ="bus" }, +}; +/** * __pci_reset_function_locked - reset a PCI device function while holding * the @dev mutex lock.
@@ -5123,65 +5144,61 @@ static void pci_dev_restore(struct pci_dev *dev)*/ int __pci_reset_function_locked (struct pci_dev *dev) { -int rc; +int i, m, rc = -ENOTTY ;might_sleep ();/* -* A reset method returns -ENOTTY if it doesn't support this device -* and we should try the next method. +* A reset method returns -ENOTTY if it doesn't support this device and +* we should try the next method. * -* If it returns 0 (success), we're finished. If it returns any -* other error, we're also finished: this indicates that further -* reset mechanisms might be broken on the device. +* If it returns 0 (success), we're finished. If it returns any other +* error, we're also finished: this indicates that further reset +* mechanisms might be broken on the device. */ - rc =pci_dev_specific_reset (dev,0 ); -if (rc != -ENOTTY ) -return rc; - rc =pcie_reset_flr (dev,0 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_af_flr (dev,0 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_pm_reset (dev,0 ); -if (rc != -ENOTTY ) -return rc; -return pci_reset_bus_function (dev,0 ); +for (i =0 ; i <PCI_NUM_RESET_METHODS && (m = dev->reset_methods[i]); i++) { + rc = pci_reset_fn_methods[m].reset_fn (dev,0 ); +if (!rc) +return 0 ; +if (rc != -ENOTTY ) +return rc; + } + +return -ENOTTY ; }EXPORT_SYMBOL_GPL (__pci_reset_function_locked);/** -* pci_probe_reset_function - check whether the device can be safely reset -* @dev: PCI device to reset +* pci_init_reset_methods - check whether device can be safely reset +* and store supported reset mechanisms. +* @dev: PCI device to check for reset mechanisms * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive -* to PCI config space in order to use this function. +* to reads and writes to its PCI config space in order to use this function. * -* Returns 0 if the device function can be reset or negative if the -* device doesn't support resetting a single function. +* Stores reset mechanisms supported by device in reset_methods byte array +* which is a member of struct pci_dev. */ -int pci_probe_reset_function (struct pci_dev *dev) +void pci_init_reset_methods (struct pci_dev *dev) { -int rc; +int i, n, rc; +u8 reset_methods[PCI_NUM_RESET_METHODS ] = {0 }; -might_sleep (); + n =0 ; - rc =pci_dev_specific_reset (dev,1 ); -if (rc != -ENOTTY ) -return rc; - rc =pcie_reset_flr (dev,1 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_af_flr (dev,1 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_pm_reset (dev,1 ); -if (rc != -ENOTTY ) -return rc; +BUILD_BUG_ON (ARRAY_SIZE (pci_reset_fn_methods) !=PCI_NUM_RESET_METHODS ); -return pci_reset_bus_function (dev,1 ); +might_sleep (); + +for (i =1 ; i <PCI_NUM_RESET_METHODS ; i++) { + rc = pci_reset_fn_methods[i].reset_fn (dev,1 ); +if (!rc) + reset_methods[n++] = i; +else if (rc != -ENOTTY ) +break ; + } +memcpy (dev->reset_methods, reset_methods,sizeof (reset_methods)); }/**
drivers/pci/pci.h +8 -1
@@ -33,7 +33,8 @@ enum pci_mmap_api {int pci_mmap_fits (struct pci_dev *pdev,int resno,struct vm_area_struct *vmai,enum pci_mmap_api mmap_api); -int pci_probe_reset_function (struct pci_dev *dev); +int pci_reset_supported (struct pci_dev *dev); +void pci_init_reset_methods (struct pci_dev *dev);int pci_bridge_secondary_bus_reset (struct pci_dev *dev);int pci_bus_error_reset (struct pci_dev *dev);
@@ -606,6 +607,12 @@ struct pci_dev_reset_methods {int (*reset)(struct pci_dev *dev,int probe); }; +struct pci_reset_fn_method { +int (*reset_fn)(struct pci_dev *pdev,int probe); +char *name; +}; + +extern const struct pci_reset_fn_method pci_reset_fn_methods[];#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_reset (struct pci_dev *dev,int probe);#else
drivers/pci/probe.c +2 -3
@@ -2406,9 +2406,8 @@ static void pci_init_capabilities(struct pci_dev *dev)pci_rcec_init (dev);/* Root Complex Event Collector */ pcie_report_downtraining (dev); - -if (pci_probe_reset_function (dev) ==0 ) - dev->reset_fn =1 ; +pci_init_reset_methods (dev); + dev->reset_fn =pci_reset_supported (dev); }/*
include/linux/pci.h +7 -0
@@ -49,6 +49,9 @@ PCI_STATUS_SIG_TARGET_ABORT | \ PCI_STATUS_PARITY) +/* Number of reset methods used in pci_reset_fn_methods array in pci.c */ +#define PCI_NUM_RESET_METHODS 6 +/* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded
@@ -504,6 +507,10 @@ struct pci_dev {char *driver_override;/* Driver name to force a match */ unsigned long priv_flags;/* Private flags for the PCI driver */ +/* +* See pci_reset_fn_methods array in pci.c for ordering. +*/ +u8 reset_methods[PCI_NUM_RESET_METHODS ];/* Reset methods ordered by priority */ };static inline struct pci_dev *pci_physfn (struct pci_dev *dev)
Signature · 1 line
2.32.0
Re: [PATCH v8 2/8] PCI: Add new array for keeping track of ordering of reset methods
Quoted 36 lines · On Tue, 29 Jun 2021 21:30:58 +0530 Amey Narkhede <[email protected]>…
Introduce a new array
reset_methodsin structpci_devto keep track of reset mechanisms supported by the device and their ordering.Also refactor probing and reset functions to take advantage of calling convention of reset functions.
Co-developed-by Alex Williamson <[email protected]>Signed-off-by Alex Williamson <[email protected]>Signed-off-by Amey Narkhede <[email protected]>--- drivers/pci/pci.c | 97 ++++++++++++++++++++++++++------------------- drivers/pci/pci.h | 9 ++++- drivers/pci/probe.c | 5 +-- include/linux/pci.h | 7 ++++ 4 files changed, 74 insertions(+), 44 deletions(-)drivers/pci/pci.c +8
-0@@ -72,6 +72,14 @@ static void pci_dev_d3_sleep(struct pci_dev *dev)msleep (delay); } +int pci_reset_supported (struct pci_dev *dev) +{ +u8 null_reset_methods[PCI_NUM_RESET_METHODS ] = {0 }; + +return memcmp (null_reset_methods, + dev->reset_methods,sizeof (null_reset_methods)); +} +#ifdef CONFIG_PCI_DOMAINS int pci_domains_supported =1 ;#endif
drivers/pci/pci.c static void pci_dev_restore(struct pci_dev *dev) · line 5115
Quoted 7 lines
drivers/pci/pci.c +4
-0@@ -5101,6 +5109,19 @@ static void pci_dev_restore(struct pci_dev *dev) err_handler->reset_done (dev); } +/* +* The ordering for functions in pci_reset_fn_methods is required for +* reset_methods byte array defined in struct pci_dev. +*/
Is this comment still relevant? Ordering here defines the default priority scheme, but now that index=priority rather than index=method in reset_methods, I'm not sure these comments are very clear. Thanks,
Alex
Quoted 182 lines
drivers/pci/pci.c +45
-40+const struct pci_reset_fn_method pci_reset_fn_methods[] = { + { }, + { &pci_dev_specific_reset, .name ="device_specific" }, + { &pcie_reset_flr, .name ="flr" }, + { &pci_af_flr, .name ="af_flr" }, + { &pci_pm_reset, .name ="pm" }, + { &pci_reset_bus_function, .name ="bus" }, +}; +/** * __pci_reset_function_locked - reset a PCI device function while holding * the @dev mutex lock. @@ -5123,65 +5144,61 @@ static void pci_dev_restore(struct pci_dev *dev)*/ int __pci_reset_function_locked (struct pci_dev *dev) { -int rc; +int i, m, rc = -ENOTTY ;might_sleep ();/* -* A reset method returns -ENOTTY if it doesn't support this device -* and we should try the next method. +* A reset method returns -ENOTTY if it doesn't support this device and +* we should try the next method. * -* If it returns 0 (success), we're finished. If it returns any -* other error, we're also finished: this indicates that further -* reset mechanisms might be broken on the device. +* If it returns 0 (success), we're finished. If it returns any other +* error, we're also finished: this indicates that further reset +* mechanisms might be broken on the device. */ - rc =pci_dev_specific_reset (dev,0 ); -if (rc != -ENOTTY ) -return rc; - rc =pcie_reset_flr (dev,0 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_af_flr (dev,0 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_pm_reset (dev,0 ); -if (rc != -ENOTTY ) -return rc; -return pci_reset_bus_function (dev,0 ); +for (i =0 ; i <PCI_NUM_RESET_METHODS && (m = dev->reset_methods[i]); i++) { + rc = pci_reset_fn_methods[m].reset_fn (dev,0 ); +if (!rc) +return 0 ; +if (rc != -ENOTTY ) +return rc; + } + +return -ENOTTY ; }EXPORT_SYMBOL_GPL (__pci_reset_function_locked);/** -* pci_probe_reset_function - check whether the device can be safely reset -* @dev: PCI device to reset +* pci_init_reset_methods - check whether device can be safely reset +* and store supported reset mechanisms. +* @dev: PCI device to check for reset mechanisms * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive -* to PCI config space in order to use this function. +* to reads and writes to its PCI config space in order to use this function. * -* Returns 0 if the device function can be reset or negative if the -* device doesn't support resetting a single function. +* Stores reset mechanisms supported by device in reset_methods byte array +* which is a member of struct pci_dev. */ -int pci_probe_reset_function (struct pci_dev *dev) +void pci_init_reset_methods (struct pci_dev *dev) { -int rc; +int i, n, rc; +u8 reset_methods[PCI_NUM_RESET_METHODS ] = {0 }; -might_sleep (); + n =0 ; - rc =pci_dev_specific_reset (dev,1 ); -if (rc != -ENOTTY ) -return rc; - rc =pcie_reset_flr (dev,1 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_af_flr (dev,1 ); -if (rc != -ENOTTY ) -return rc; - rc =pci_pm_reset (dev,1 ); -if (rc != -ENOTTY ) -return rc; +BUILD_BUG_ON (ARRAY_SIZE (pci_reset_fn_methods) !=PCI_NUM_RESET_METHODS ); -return pci_reset_bus_function (dev,1 ); +might_sleep (); + +for (i =1 ; i <PCI_NUM_RESET_METHODS ; i++) { + rc = pci_reset_fn_methods[i].reset_fn (dev,1 ); +if (!rc) + reset_methods[n++] = i; +else if (rc != -ENOTTY ) +break ; + } +memcpy (dev->reset_methods, reset_methods,sizeof (reset_methods)); }/** drivers/pci/pci.h +8
-1@@ -33,7 +33,8 @@ enum pci_mmap_api {int pci_mmap_fits (struct pci_dev *pdev,int resno,struct vm_area_struct *vmai,enum pci_mmap_api mmap_api); -int pci_probe_reset_function (struct pci_dev *dev); +int pci_reset_supported (struct pci_dev *dev); +void pci_init_reset_methods (struct pci_dev *dev);int pci_bridge_secondary_bus_reset (struct pci_dev *dev);int pci_bus_error_reset (struct pci_dev *dev);@@ -606,6 +607,12 @@ struct pci_dev_reset_methods {int (*reset)(struct pci_dev *dev,int probe); }; +struct pci_reset_fn_method { +int (*reset_fn)(struct pci_dev *pdev,int probe); +char *name; +}; + +extern const struct pci_reset_fn_method pci_reset_fn_methods[];#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_reset (struct pci_dev *dev,int probe);#else drivers/pci/probe.c +2
-3@@ -2406,9 +2406,8 @@ static void pci_init_capabilities(struct pci_dev *dev)pci_rcec_init (dev);/* Root Complex Event Collector */ pcie_report_downtraining (dev); - -if (pci_probe_reset_function (dev) ==0 ) - dev->reset_fn =1 ; +pci_init_reset_methods (dev); + dev->reset_fn =pci_reset_supported (dev); }/* include/linux/pci.h +7
-0@@ -49,6 +49,9 @@ PCI_STATUS_SIG_TARGET_ABORT | \ PCI_STATUS_PARITY) +/* Number of reset methods used in pci_reset_fn_methods array in pci.c */ +#define PCI_NUM_RESET_METHODS 6 +/* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded @@ -504,6 +507,10 @@ struct pci_dev {char *driver_override;/* Driver name to force a match */ unsigned long priv_flags;/* Private flags for the PCI driver */ +/* +* See pci_reset_fn_methods array in pci.c for ordering. +*/ +u8 reset_methods[PCI_NUM_RESET_METHODS ];/* Reset methods ordered by priority */ };static inline struct pci_dev *pci_physfn (struct pci_dev *dev)
PATCH v8 3/8 PCI: Remove reset_fn field from pci_dev
In reply to Amey Narkhedereset_fn field is used to indicate whether the device supports any reset mechanism or not. Remove the use of reset_fn in favor of new reset_methods array which can be used to keep track of all supported reset mechanisms of a device and their ordering.
The octeon driver is incorrectly using reset_fn field to detect if the device supports FLR or not. Use pcie_reset_flr() to probe whether it supports FLR or not.
--- drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 2 +- drivers/pci/pci-sysfs.c | 2 +- drivers/pci/pci.c | 6 +++--- drivers/pci/probe.c | 1 - drivers/pci/quirks.c | 2 +- drivers/pci/remove.c | 1 - include/linux/pci.h | 1 - 7 files changed, 6 insertions(+), 9 deletions(-)
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +1 -1
@@ -526,7 +526,7 @@ static void octeon_destroy_resources(struct octeon_device *oct) oct->irq_name_storage =NULL ; }/* Soft reset the octeon device before exiting */ -if (oct->pci_dev->reset_fn) +if (!pcie_reset_flr (oct->pci_dev,1 ))octeon_pci_flr (oct);else cn23xx_vf_ask_pf_to_do_flr (oct);
drivers/pci/pci-sysfs.c +1 -1
@@ -1367,7 +1367,7 @@ static umode_t pci_dev_reset_attr_is_visible(struct kobject *kobj, {struct pci_dev *pdev =to_pci_dev (kobj_to_dev (kobj)); -if (!pdev->reset_fn) +if (!pci_reset_supported (pdev))return 0 ;return a->mode;
drivers/pci/pci.c +3 -3
@@ -5221,7 +5221,7 @@ int pci_reset_function(struct pci_dev *dev) {int rc; -if (!dev->reset_fn) +if (!pci_reset_supported (dev))return -ENOTTY ;pci_dev_lock (dev);
@@ -5257,7 +5257,7 @@ int pci_reset_function_locked(struct pci_dev *dev) {int rc; -if (!dev->reset_fn) +if (!pci_reset_supported (dev))return -ENOTTY ;pci_dev_save_and_disable (dev);
@@ -5280,7 +5280,7 @@ int pci_try_reset_function(struct pci_dev *dev) {int rc; -if (!dev->reset_fn) +if (!pci_reset_supported (dev))return -ENOTTY ;if (!pci_dev_trylock (dev))
drivers/pci/probe.c +0 -1
@@ -2407,7 +2407,6 @@ static void pci_init_capabilities(struct pci_dev *dev)pcie_report_downtraining (dev);pci_init_reset_methods (dev); - dev->reset_fn =pci_reset_supported (dev); }/*
drivers/pci/quirks.c +1 -1
@@ -5589,7 +5589,7 @@ static void quirk_reset_lenovo_thinkpad_p50_nvgpu(struct pci_dev *pdev)if (pdev->subsystem_vendor !=PCI_VENDOR_ID_LENOVO || pdev->subsystem_device !=0x222e || - !pdev->reset_fn) + !pci_reset_supported (pdev))return ;if (pci_enable_device_mem (pdev))
drivers/pci/remove.c +0 -1
@@ -19,7 +19,6 @@ static void pci_stop_dev(struct pci_dev *dev)pci_pme_active (dev, false);if (pci_dev_is_added (dev)) { - dev->reset_fn =0 ;device_release_driver (&dev->dev);pci_proc_detach_device (dev);
include/linux/pci.h +0 -1
@@ -429,7 +429,6 @@ struct pci_dev { unsigned int state_saved:1; unsigned int is_physfn:1; unsigned int is_virtfn:1; - unsigned int reset_fn:1; unsigned int is_hotplug_bridge:1; unsigned int shpc_managed:1; /* SHPC owned by shpchp */ unsigned int is_thunderbolt:1; /* Thunderbolt controller */
Signature · 1 line
2.32.0
PATCH v8 4/8 PCI/sysfs: Allow userspace to query and set device reset mechanism
In reply to Amey NarkhedeAdd reset_method sysfs attribute to enable user to query and set user preferred device reset methods and their ordering.
--- Documentation/ABI/testing/sysfs-bus-pci | 19 +++++ drivers/pci/pci-sysfs.c | 102 ++++++++++++++++++++++++ drivers/pci/pci.c | 1 + 3 files changed, 122 insertions(+)
Documentation/ABI/testing/sysfs-bus-pci +19 -0
@@ -121,6 +121,25 @@ Description: child buses, and re-discover devices removed earlier from this part of the device tree. +What: /sys/bus/pci/devices/.../reset_method +Date: March 2021 +Contact: Amey Narkhede <[email protected]> +Description: + Some devices allow an individual function to be reset + without affecting other functions in the same slot. + + For devices that have this support, a file named + reset_method will be present in sysfs. Initially reading + this file will give names of the device supported reset + methods and their ordering. After write, this file will + give names and ordering of currently enabled reset methods. + Writing the name or comma separated list of names of any of + the device supported reset methods to this file will set + the reset methods and their ordering to be used when + resetting the device. Writing empty string to this file + will disable ability to reset the device and writing + "default" will return to the original value. + What: /sys/bus/pci/devices/.../reset Date: July 2009 Contact: Michael S. Tsirkin <[email protected]>
drivers/pci/pci-sysfs.c +102 -0
114 lines not on this page · raw message
drivers/pci/pci.c +1 -0
@@ -5198,6 +5198,7 @@ void pci_init_reset_methods(struct pci_dev *dev)else if (rc != -ENOTTY )break ; } +memcpy (dev->reset_methods, reset_methods,sizeof (reset_methods)); }
Signature · 1 line
2.32.0
Re: [PATCH v8 4/8] PCI/sysfs: Allow userspace to query and set device reset mechanism
Quoted 51 lines · On Tue, 29 Jun 2021 21:31:00 +0530 Amey Narkhede <[email protected]>…
Add
reset_methodsysfs attribute to enable user to query and set user preferred device reset methods and their ordering.Co-developed-by Alex Williamson <[email protected]>Signed-off-by Alex Williamson <[email protected]>Signed-off-by Amey Narkhede <[email protected]>--- Documentation/ABI/testing/sysfs-bus-pci | 19 +++++ drivers/pci/pci-sysfs.c | 102 ++++++++++++++++++++++++ drivers/pci/pci.c | 1 + 3 files changed, 122 insertions(+)Documentation/ABI/testing/sysfs-bus-pci +19
-0@@ -121,6 +121,25 @@ Description: child buses, and re-discover devices removed earlier from this part of the device tree. +What: /sys/bus/pci/devices/.../reset_method +Date: March 2021 +Contact: Amey Narkhede <[email protected]> +Description: + Some devices allow an individual function to be reset + without affecting other functions in the same slot. + + For devices that have this support, a file named + reset_method will be present in sysfs. Initially reading + this file will give names of the device supported reset + methods and their ordering. After write, this file will + give names and ordering of currently enabled reset methods. + Writing the name or comma separated list of names of any of + the device supported reset methods to this file will set + the reset methods and their ordering to be used when + resetting the device. Writing empty string to this file + will disable ability to reset the device and writing + "default" will return to the original value. + What: /sys/bus/pci/devices/.../reset Date: July 2009 Contact: Michael S. Tsirkin <[email protected]>drivers/pci/pci-sysfs.c +1
-0@@ -1334,6 +1334,107 @@ static const struct attribute_group pci_dev_rom_attr_group = { .is_bin_visible = pci_dev_rom_attr_is_visible, }; +static ssize_t reset_method_show(struct device *dev,
drivers/pci/pci-sysfs.c static const struct attribute_group pci_dev_rom_attr_group = { · line 1347
Quoted 10 lines
drivers/pci/pci-sysfs.c +10
-0+struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); +ssize_t len =0 ; +int i, idx; + +for (i =0 ; i <PCI_NUM_RESET_METHODS ; i++) { + idx = pdev->reset_methods[i]; +if (idx)
Given the new encoding, shouldn't this be:
if (!idx) break;
For example if we had [1, 0, 2,...] (which should be impossible) then __pci_reset_function_locked() would stop at the first zero, but the logic here would cause sysfs to print "device_specific,flr".
Quoted 15 lines
drivers/pci/pci-sysfs.c +15
-0+ len +=sysfs_emit_at (buf, len,"%s%s" , len ?"," :"" , + pci_reset_fn_methods[idx].name); + } + +if (len) + len +=sysfs_emit_at (buf, len,"\n" ); + +return len; +} + +static ssize_t reset_method_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct pci_dev *pdev =to_pci_dev (dev);
drivers/pci/pci-sysfs.c static const struct attribute_group pci_dev_rom_attr_group = { · line 1372
Quoted 10 lines
drivers/pci/pci-sysfs.c +10
-0+int i, n; +char *name, *options; +u8 reset_methods[PCI_NUM_RESET_METHODS ] = {0 }; + +if (count >= (PAGE_SIZE -1 )) +return -EINVAL ; + +if (sysfs_streq (buf,"" )) { +pci_warn (pdev,"All device reset methods disabled by user" ); +memset (pdev->reset_methods,0 ,PCI_NUM_RESET_METHODS );
If options were initialized to NULL, this could be a goto before the memcpy below.
drivers/pci/pci-sysfs.c static const struct attribute_group pci_dev_rom_attr_group = { · line 1385
Quoted 13 lines
drivers/pci/pci-sysfs.c +13
-0+return count; + } + +if (sysfs_streq (buf,"default" )) { +pci_init_reset_methods (pdev); +return count; + } + + options =kstrndup (buf, count,GFP_KERNEL ); +if (!options) +return -ENOMEM ; + + n =0 ;
nit, initialize in declaration. Looks like @i could also be scoped within the below loop.
Quoted 68 lines
drivers/pci/pci-sysfs.c +53
-0+ +while ((name =strsep (&options,"," )) !=NULL ) { +if (sysfs_streq (name,"" )) +continue ; + + name =strim (name); + +for (i =1 ; i <PCI_NUM_RESET_METHODS ; i++) { +if (sysfs_streq (name, pci_reset_fn_methods[i].name) && + !pci_reset_fn_methods[i].reset_fn (pdev,1 )) { + reset_methods[n++] = i; +break ; + } + } + +if (i ==PCI_NUM_RESET_METHODS ) { +kfree (options); +return -EINVAL ; + } + } + +if (!pci_reset_fn_methods[1 ].reset_fn (pdev,1 ) && reset_methods[0 ] !=1 ) +pci_warn (pdev,"Device specific reset disabled/de-prioritized by user" ); + +memcpy (pdev->reset_methods, reset_methods,sizeof (reset_methods)); +kfree (options); + +return count; +} +static DEVICE_ATTR_RW (reset_method); + +static struct attribute *pci_dev_reset_method_attrs[] = { + &dev_attr_reset_method.attr, +NULL , +}; + +static umode_t pci_dev_reset_method_attr_is_visible (struct kobject *kobj, +struct attribute *a,int n) +{ +struct pci_dev *pdev =to_pci_dev (kobj_to_dev (kobj)); + +if (!pci_reset_supported (pdev)) +return 0 ; + +return a->mode; +} + +static const struct attribute_group pci_dev_reset_method_attr_group = { + .attrs = pci_dev_reset_method_attrs, + .is_visible = pci_dev_reset_method_attr_is_visible, +}; +static ssize_t reset_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) {@@ -1491,6 +1592,7 @@ const struct attribute_group *pci_dev_groups[] = { &pci_dev_config_attr_group, &pci_dev_rom_attr_group, &pci_dev_reset_attr_group, + &pci_dev_reset_method_attr_group, &pci_dev_vpd_attr_group, #ifdef CONFIG_DMI &pci_dev_smbios_attr_group,drivers/pci/pci.c +0
-0
drivers/pci/pci.c void pci_init_reset_methods(struct pci_dev *dev) · line 5204
Quoted 7 lines
drivers/pci/pci.c +1
-0@@ -5198,6 +5198,7 @@ void pci_init_reset_methods(struct pci_dev *dev)else if (rc != -ENOTTY )break ; } +memcpy (dev->reset_methods, reset_methods,sizeof (reset_methods)); }
Do this cleanup where it was introduced in patch 2/ Thanks,
Alex
PATCH v8 5/8 PCI: Define a function to set ACPI_COMPANION in pci_dev
In reply to Amey NarkhedeFrom: Shanker Donthineni <[email protected]>
Move the existing code logic from acpi_pci_bridge_d3() to a separate function pci_set_acpi_fwnode() to set the ACPI fwnode.
No functional change with this patch.
--- drivers/pci/pci-acpi.c | 12 ++++++++---- drivers/pci/pci.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-)
drivers/pci/pci-acpi.c +8 -4
@@ -934,6 +934,13 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)static struct acpi_device *acpi_pci_find_companion (struct device *dev); +void pci_set_acpi_fwnode (struct pci_dev *dev) +{ +if (!ACPI_COMPANION (&dev->dev) && !pci_dev_is_added (dev)) +ACPI_COMPANION_SET (&dev->dev, +acpi_pci_find_companion (&dev->dev)); +} +static bool acpi_pci_bridge_d3 (struct pci_dev *dev) {const struct fwnode_handle *fwnode;
@@ -945,11 +952,8 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev)return false;/* Assume D3 support if the bridge is power-manageable by ACPI. */ +pci_set_acpi_fwnode (dev); adev =ACPI_COMPANION (&dev->dev); -if (!adev && !pci_dev_is_added (dev)) { - adev =acpi_pci_find_companion (&dev->dev); -ACPI_COMPANION_SET (&dev->dev, adev); - }if (adev &&acpi_device_power_manageable (adev))return true;
drivers/pci/pci.h +2 -0
@@ -704,7 +704,9 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL#ifdef CONFIG_ACPI int pci_acpi_program_hp_params (struct pci_dev *dev);extern const struct attribute_group pci_dev_acpi_attr_group; +void pci_set_acpi_fwnode (struct pci_dev *dev);#else +static inline void pci_set_acpi_fwnode (struct pci_dev *dev) {}static inline int pci_acpi_program_hp_params (struct pci_dev *dev) {return -ENODEV ;
Signature · 1 line
2.32.0
PATCH v8 6/8 PCI: Setup ACPI fwnode early and at the same time with OF
In reply to Amey NarkhedeFrom: Shanker Donthineni <[email protected]>
The pci_dev objects are created through two mechanisms 1) during PCI bus scan and 2) from I/O Virtualization. The fwnode in pci_dev object is being set at different places depends on the type of firmware used, device creation mechanism, and acpi_pci_bridge_d3() WAR.
The software features which have a dependency on ACPI fwnode properties and need to be handled before device_add() will not work. One use case, the software has to check the existence of _RST method to support ACPI based reset method.
This patch does the two changes in order to provide fwnode consistently.
- Set ACPI and OF fwnodes from pci_setup_device().
- Remove pci_set_acpi_fwnode() in acpi_pci_bridge_d3().
After this patch, ACPI/OF firmware properties are visible at the same time during the early stage of pci_dev setup. And also call sites should be able to use firmware agnostic functions device_property_xxx() for the early PCI quirks in the future.
--- drivers/pci/pci-acpi.c | 1 - drivers/pci/probe.c | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/pci/pci-acpi.c +0 -1
@@ -952,7 +952,6 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev)return false;/* Assume D3 support if the bridge is power-manageable by ACPI. */ -pci_set_acpi_fwnode (dev); adev =ACPI_COMPANION (&dev->dev);if (adev &&acpi_device_power_manageable (adev))
drivers/pci/probe.c +4 -3
@@ -1790,6 +1790,9 @@ int pci_setup_device(struct pci_dev *dev) dev->error_state = pci_channel_io_normal;set_pcie_port_type (dev); +pci_set_of_node (dev); +pci_set_acpi_fwnode (dev); +pci_dev_assign_slot (dev);/*
@@ -1925,6 +1928,7 @@ int pci_setup_device(struct pci_dev *dev)default :/* unknown header */ pci_err (dev,"unknown header type %02x, ignoring device\n" , dev->hdr_type); +pci_release_of_node (dev);return -EIO ; bad:
@@ -2352,10 +2356,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ; -pci_set_of_node (dev); -if (pci_setup_device (dev)) { -pci_release_of_node (dev);pci_bus_put (dev->bus);kfree (dev);return NULL ;
Signature · 1 line
2.32.0
PATCH v8 7/8 PCI: Add support for ACPI _RST reset method
In reply to Amey NarkhedeFrom: Shanker Donthineni <[email protected]>
The _RST is a standard method specified in the ACPI specification. It provides a function level reset when it is described in the acpi_device context associated with PCI-device. Implement a new reset function pci_dev_acpi_reset() for probing RST method and execute if it is defined in the firmware.
The default priority of the ACPI reset is set to below device-specific and above hardware resets.
--- drivers/pci/pci-acpi.c | 23 +++++++++++++++++++++++ drivers/pci/pci.c | 1 + drivers/pci/pci.h | 6 ++++++ include/linux/pci.h | 2 +- 4 files changed, 31 insertions(+), 1 deletion(-)
drivers/pci/pci-acpi.c +23 -0
@@ -941,6 +941,29 @@ void pci_set_acpi_fwnode(struct pci_dev *dev) acpi_pci_find_companion(&dev->dev)); } +/** +* pci_dev_acpi_reset - do a function level reset using _RST method +* @dev: device to reset +* @probe: check if _RST method is included in the acpi_device context. +*/ +int pci_dev_acpi_reset (struct pci_dev *dev,int probe) +{ +acpi_handle handle =ACPI_HANDLE (&dev->dev); + +if (!handle || !acpi_has_method (handle,"_RST" )) +return -ENOTTY ; + +if (probe) +return 0 ; + +if (ACPI_FAILURE (acpi_evaluate_object (handle,"_RST" ,NULL ,NULL ))) { +pci_warn (dev,"ACPI _RST failed\n" ); +return -EINVAL ; + } + +return 0 ; +} +static bool acpi_pci_bridge_d3 (struct pci_dev *dev) {const struct fwnode_handle *fwnode;
drivers/pci/pci.c +1 -0
@@ -5116,6 +5116,7 @@ static void pci_dev_restore(struct pci_dev *dev)const struct pci_reset_fn_method pci_reset_fn_methods[] = { { }, { &pci_dev_specific_reset, .name ="device_specific" }, + { &pci_dev_acpi_reset, .name ="acpi" }, { &pcie_reset_flr, .name ="flr" }, { &pci_af_flr, .name ="af_flr" }, { &pci_pm_reset, .name ="pm" },
drivers/pci/pci.h +6 -0
@@ -705,7 +705,13 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVALint pci_acpi_program_hp_params (struct pci_dev *dev);extern const struct attribute_group pci_dev_acpi_attr_group;void pci_set_acpi_fwnode (struct pci_dev *dev); +int pci_dev_acpi_reset (struct pci_dev *dev,int probe);#else +static inline int pci_dev_acpi_reset (struct pci_dev *dev,int probe) +{ +return -ENOTTY ; +} +static inline void pci_set_acpi_fwnode (struct pci_dev *dev) {}static inline int pci_acpi_program_hp_params (struct pci_dev *dev) {
include/linux/pci.h +1 -1
@@ -50,7 +50,7 @@ PCI_STATUS_PARITY)/* Number of reset methods used in pci_reset_fn_methods array in pci.c */ -#define PCI_NUM_RESET_METHODS 6 +#define PCI_NUM_RESET_METHODS 7/* * The PCI interface treats multi-function devices as independent
Signature · 1 line
2.32.0
PATCH v8 8/8 PCI: Change the type of probe argument in reset functions
In reply to Amey NarkhedeIntroduce a new enum pci_reset_mode_t to make the context of probe argument in reset functions clear and the code easier to read. Change the type of probe argument in functions which implement reset methods from int to pci_reset_mode_t to make the intent clear.
Add a new line in return statement of pci_reset_bus_function().
--- drivers/crypto/cavium/nitrox/nitrox_main.c | 2 +- .../ethernet/cavium/liquidio/lio_vf_main.c | 2 +- drivers/pci/hotplug/pciehp.h | 2 +- drivers/pci/hotplug/pciehp_hpc.c | 4 +- drivers/pci/pci-acpi.c | 10 ++- drivers/pci/pci-sysfs.c | 6 +- drivers/pci/pci.c | 85 ++++++++++++------- drivers/pci/pci.h | 12 +-- drivers/pci/pcie/aer.c | 2 +- drivers/pci/quirks.c | 37 ++++---- include/linux/pci.h | 8 +- include/linux/pci_hotplug.h | 2 +- 12 files changed, 105 insertions(+), 67 deletions(-)
drivers/crypto/cavium/nitrox/nitrox_main.c +1 -1
@@ -306,7 +306,7 @@ static int nitrox_device_flr(struct pci_dev *pdev)return -ENOMEM ; } -pcie_reset_flr (pdev,0 ); +pcie_reset_flr (pdev,PCI_RESET_DO_RESET );pci_restore_state (pdev);
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +1 -1
@@ -526,7 +526,7 @@ static void octeon_destroy_resources(struct octeon_device *oct) oct->irq_name_storage =NULL ; }/* Soft reset the octeon device before exiting */ -if (!pcie_reset_flr (oct->pci_dev,1 )) +if (!pcie_reset_flr (oct->pci_dev,PCI_RESET_PROBE ))octeon_pci_flr (oct);else cn23xx_vf_ask_pf_to_do_flr (oct);
drivers/pci/hotplug/pciehp.h +1 -1
@@ -181,7 +181,7 @@ void pciehp_release_ctrl(struct controller *ctrl);int pciehp_sysfs_enable_slot (struct hotplug_slot *hotplug_slot);int pciehp_sysfs_disable_slot (struct hotplug_slot *hotplug_slot); -int pciehp_reset_slot (struct hotplug_slot *hotplug_slot,int probe); +int pciehp_reset_slot (struct hotplug_slot *hotplug_slot,pci_reset_mode_t mode);int pciehp_get_attention_status (struct hotplug_slot *hotplug_slot,u8 *status);int pciehp_set_raw_indicator_status (struct hotplug_slot *h_slot,u8 status);int pciehp_get_raw_indicator_status (struct hotplug_slot *h_slot,u8 *status);
drivers/pci/hotplug/pciehp_hpc.c +2 -2
@@ -834,14 +834,14 @@ void pcie_disable_interrupt(struct controller *ctrl)* momentarily, if we see that they could interfere. Also, clear any spurious * events after. */ -int pciehp_reset_slot (struct hotplug_slot *hotplug_slot,int probe) +int pciehp_reset_slot (struct hotplug_slot *hotplug_slot,pci_reset_mode_t mode) {struct controller *ctrl =to_ctrl (hotplug_slot);struct pci_dev *pdev =ctrl_dev (ctrl);u16 stat_mask =0 , ctrl_mask =0 ;int rc; -if (probe) +if (mode ==PCI_RESET_PROBE )return 0 ;down_write (&ctrl->reset_lock);
drivers/pci/pci-acpi.c +7 -3
@@ -944,16 +944,20 @@ void pci_set_acpi_fwnode(struct pci_dev *dev)/** * pci_dev_acpi_reset - do a function level reset using _RST method * @dev: device to reset -* @probe: check if _RST method is included in the acpi_device context. +* @probe: If PCI_RESET_PROBE, check whether _RST method is included +* in the acpi_device context. */ -int pci_dev_acpi_reset (struct pci_dev *dev,int probe) +int pci_dev_acpi_reset (struct pci_dev *dev,pci_reset_mode_t mode) {acpi_handle handle =ACPI_HANDLE (&dev->dev); +if (mode >=PCI_RESET_MODE_MAX ) +return -EINVAL ; +if (!handle || !acpi_has_method (handle,"_RST" ))return -ENOTTY ; -if (probe) +if (mode ==PCI_RESET_PROBE )return 0 ;if (ACPI_FAILURE (acpi_evaluate_object (handle,"_RST" ,NULL ,NULL ))) {
drivers/pci/pci-sysfs.c +4 -2
@@ -1392,7 +1392,8 @@ static ssize_t reset_method_store(struct device *dev,for (i =1 ; i <PCI_NUM_RESET_METHODS ; i++) {if (sysfs_streq (name, pci_reset_fn_methods[i].name) && - !pci_reset_fn_methods[i].reset_fn (pdev,1 )) { + !pci_reset_fn_methods[i].reset_fn (pdev, +PCI_RESET_PROBE )) { reset_methods[n++] = i;break ; }
@@ -1404,7 +1405,8 @@ static ssize_t reset_method_store(struct device *dev, } } -if (!pci_reset_fn_methods[1 ].reset_fn (pdev,1 ) && reset_methods[0 ] !=1 ) +if (!pci_reset_fn_methods[1 ].reset_fn (pdev,PCI_RESET_PROBE ) && + reset_methods[0 ] !=1 )pci_warn (pdev,"Device specific reset disabled/de-prioritized by user" );memcpy (pdev->reset_methods, reset_methods,sizeof (reset_methods));
drivers/pci/pci.c +53 -32
263 lines not on this page · raw message
drivers/pci/pci.h +6 -6
@@ -604,19 +604,19 @@ static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)struct pci_dev_reset_methods {u16 vendor;u16 device; -int (*reset)(struct pci_dev *dev,int probe); +int (*reset)(struct pci_dev *dev,pci_reset_mode_t mode); };struct pci_reset_fn_method { -int (*reset_fn)(struct pci_dev *pdev,int probe); +int (*reset_fn)(struct pci_dev *pdev,pci_reset_mode_t mode);char *name; };extern const struct pci_reset_fn_method pci_reset_fn_methods[];#ifdef CONFIG_PCI_QUIRKS -int pci_dev_specific_reset (struct pci_dev *dev,int probe); +int pci_dev_specific_reset (struct pci_dev *dev,pci_reset_mode_t mode);#else -static inline int pci_dev_specific_reset (struct pci_dev *dev,int probe) +static inline int pci_dev_specific_reset (struct pci_dev *dev,pci_reset_mode_t mode) {return -ENOTTY ; }
@@ -705,9 +705,9 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVALint pci_acpi_program_hp_params (struct pci_dev *dev);extern const struct attribute_group pci_dev_acpi_attr_group;void pci_set_acpi_fwnode (struct pci_dev *dev); -int pci_dev_acpi_reset (struct pci_dev *dev,int probe); +int pci_dev_acpi_reset (struct pci_dev *dev,pci_reset_mode_t mode);#else -static inline int pci_dev_acpi_reset (struct pci_dev *dev,int probe) +static inline int pci_dev_acpi_reset (struct pci_dev *dev,pci_reset_mode_t mode) {return -ENOTTY ; }
drivers/pci/pcie/aer.c +1 -1
@@ -1405,7 +1405,7 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) }if (type ==PCI_EXP_TYPE_RC_EC || type ==PCI_EXP_TYPE_RC_END ) { - rc =pcie_reset_flr (dev,0 ); + rc =pcie_reset_flr (dev,PCI_RESET_DO_RESET );if (!rc)pci_info (dev,"has been reset\n" );else
drivers/pci/quirks.c +21 -16
@@ -3669,7 +3669,7 @@ DECLARE_PCI_FIXUP_SUSPEND_LATE(PCI_VENDOR_ID_INTEL,* reset a single function if other methods (e.g. FLR, PM D0->D3) are * not available. */ -static int reset_intel_82599_sfp_virtfn (struct pci_dev *dev,int probe) +static int reset_intel_82599_sfp_virtfn (struct pci_dev *dev,pci_reset_mode_t mode) {/* * http://www.intel.com/content/dam/doc/datasheet/82599-10-gbe-controller-datasheet.pdf
@@ -3679,7 +3679,7 @@ static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe)* Thus we must call pcie_flr() directly without first checking if it is * supported. */ -if (!probe) +if (mode ==PCI_RESET_DO_RESET )pcie_flr (dev);return 0 ; }
@@ -3691,13 +3691,13 @@ static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe)#define NSDE_PWR_STATE 0xd0100#define IGD_OPERATION_TIMEOUT 10000/* set timeout 10 seconds */ -static int reset_ivb_igd (struct pci_dev *dev,int probe) +static int reset_ivb_igd (struct pci_dev *dev,pci_reset_mode_t mode) {void __iomem *mmio_base;unsigned long timeout;u32 val; -if (probe) +if (mode ==PCI_RESET_PROBE )return 0 ; mmio_base =pci_iomap (dev,0 ,0 );
@@ -3734,7 +3734,7 @@ static int reset_ivb_igd(struct pci_dev *dev, int probe) }/* Device-specific reset method for Chelsio T4-based adapters */ -static int reset_chelsio_generic_dev (struct pci_dev *dev,int probe) +static int reset_chelsio_generic_dev (struct pci_dev *dev,pci_reset_mode_t mode) {u16 old_command;u16 msix_flags;
@@ -3750,7 +3750,7 @@ static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe)* If this is the "probe" phase, return 0 indicating that we can * reset this device. */ -if (probe) +if (mode ==PCI_RESET_PROBE )return 0 ;/*
@@ -3812,17 +3812,17 @@ static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe)* Chapter 3: NVMe control registers * Chapter 7.3: Reset behavior */ -static int nvme_disable_and_flr (struct pci_dev *dev,int probe) +static int nvme_disable_and_flr (struct pci_dev *dev,pci_reset_mode_t mode) {void __iomem *bar;u16 cmd;u32 cfg;if (dev->class !=PCI_CLASS_STORAGE_EXPRESS || -pcie_reset_flr (dev,1 ) || !pci_resource_start (dev,0 )) +pcie_reset_flr (dev,PCI_RESET_PROBE ) || !pci_resource_start (dev,0 ))return -ENOTTY ; -if (probe) +if (mode ==PCI_RESET_PROBE )return 0 ; bar =pci_iomap (dev,0 ,NVME_REG_CC +sizeof (cfg));
@@ -3886,11 +3886,13 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)* device too soon after FLR. A 250ms delay after FLR has heuristically * proven to produce reliably working results for device assignment cases. */ -static int delay_250ms_after_flr (struct pci_dev *dev,int probe) +static int delay_250ms_after_flr (struct pci_dev *dev,pci_reset_mode_t mode) { -int ret =pcie_reset_flr (dev, probe); +int ret; + + ret =pcie_reset_flr (dev, mode); -if (probe) +if (ret || mode ==PCI_RESET_PROBE )return ret;msleep (250 );
@@ -3906,13 +3908,13 @@ static int delay_250ms_after_flr(struct pci_dev *dev, int probe)#define HINIC_OPERATION_TIMEOUT 15000/* 15 seconds */ /* Device-specific reset method for Huawei Intelligent NIC virtual functions */ -static int reset_hinic_vf_dev (struct pci_dev *pdev,int probe) +static int reset_hinic_vf_dev (struct pci_dev *pdev,pci_reset_mode_t mode) {unsigned long timeout;void __iomem *bar;u32 val; -if (probe) +if (mode ==PCI_RESET_PROBE )return 0 ; bar =pci_iomap (pdev,0 ,0 );
@@ -3983,16 +3985,19 @@ static const struct pci_dev_reset_methods pci_dev_reset_methods[] = {* because when a host assigns a device to a guest VM, the host may need * to reset the device but probably doesn't have a driver for it. */ -int pci_dev_specific_reset (struct pci_dev *dev,int probe) +int pci_dev_specific_reset (struct pci_dev *dev,pci_reset_mode_t mode) {const struct pci_dev_reset_methods *i; +if (mode >=PCI_RESET_MODE_MAX ) +return -EINVAL ; +for (i = pci_dev_reset_methods; i->reset; i++) {if ((i->vendor == dev->vendor || i->vendor == (u16 )PCI_ANY_ID ) && (i->device == dev->device || i->device == (u16 )PCI_ANY_ID )) -return i->reset (dev, probe); +return i->reset (dev, mode); }return -ENOTTY ;
include/linux/pci.h +7 -1
@@ -52,6 +52,12 @@/* Number of reset methods used in pci_reset_fn_methods array in pci.c */ #define PCI_NUM_RESET_METHODS 7 +typedef enum pci_reset_mode { +PCI_RESET_DO_RESET , +PCI_RESET_PROBE , +PCI_RESET_MODE_MAX , +}pci_reset_mode_t ; +/* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded
@@ -1230,7 +1236,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,enum pci_bus_speed *speed, enum pcie_link_width *width);void pcie_print_link_status (struct pci_dev *dev); -int pcie_reset_flr (struct pci_dev *dev,int probe); +int pcie_reset_flr (struct pci_dev *dev,pci_reset_mode_t mode);int pcie_flr (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);
include/linux/pci_hotplug.h +1 -1
@@ -44,7 +44,7 @@ struct hotplug_slot_ops {int (*get_attention_status) (struct hotplug_slot *slot,u8 *value);int (*get_latch_status) (struct hotplug_slot *slot,u8 *value);int (*get_adapter_status) (struct hotplug_slot *slot,u8 *value); -int (*reset_slot) (struct hotplug_slot *slot,int probe); +int (*reset_slot) (struct hotplug_slot *slot,pci_reset_mode_t mode); };/**
--
2.32.0