Expose and manage PCI device reset
Subsystems (5)
v3 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.
The error handling might be too verbose in the last patch ("PCI: Change the type of probe argument in reset functions"). Please let me know your comments.
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 (2):
PCI: Add support for a function level reset based on _RST method
PCI: Enable NO_BUS_RESET quirk for Nvidia GPUs
Documentation/ABI/testing/sysfs-bus-pci | 16 ++ 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 | 7 +- drivers/pci/pci-sysfs.c | 97 ++++++- drivers/pci/pci.c | 264 ++++++++++++------ drivers/pci/pci.h | 14 +- drivers/pci/pcie/aer.c | 12 +- drivers/pci/probe.c | 4 +- drivers/pci/quirks.c | 63 +++-- include/linux/pci.h | 16 +- include/linux/pci_hotplug.h | 2 +- 13 files changed, 368 insertions(+), 135 deletions(-)
--
2.31.1
PATCH v3 1/7 PCI: Add pcie_reset_flr to follow calling convention of other reset methods
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/quirks.c | 9 ++-- include/linux/pci.h | 2 +- 5 files changed, 43 insertions(+), 46 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 +33 -29
90 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/quirks.c +3 -6
@@ -3831,7 +3831,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)
@@ -3900,13 +3900,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 );
include/linux/pci.h +1 -1
@@ -1217,7 +1217,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.31.1
PATCH v3 2/7 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 | 107 ++++++++++++++++++++++++++------------------ drivers/pci/pci.h | 8 +++- drivers/pci/probe.c | 5 +-- include/linux/pci.h | 7 +++ 4 files changed, 80 insertions(+), 47 deletions(-)
drivers/pci/pci.c +64 -43
@@ -72,6 +72,14 @@ static void pci_dev_d3_sleep(struct pci_dev *dev)msleep (delay); } +bool pci_reset_supported (struct pci_dev *dev) +{ +u8 null_reset_methods[PCI_RESET_METHODS_NUM ] = {0 }; + +return memcmp (null_reset_methods, + dev->reset_methods,PCI_RESET_METHODS_NUM ); +} +#ifdef CONFIG_PCI_DOMAINS int pci_domains_supported =1 ;#endif
@@ -5068,6 +5076,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.
@@ -5090,65 +5111,65 @@ static void pci_dev_restore(struct pci_dev *dev)*/ int __pci_reset_function_locked (struct pci_dev *dev) { -int rc; +int i, rc = -ENOTTY ; +u8 prio;might_sleep (); -/* -* 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. -*/ - 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 (prio =PCI_RESET_METHODS_NUM ; prio; prio--) { +for (i =0 ; i <PCI_RESET_METHODS_NUM ; i++) { +if (dev->reset_methods[i] == prio) { +/* +* 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. +*/ + rc = pci_reset_fn_methods[i].reset_fn (dev,0 ); +if (rc != -ENOTTY ) +return rc; +break ; + } + } +if (i ==PCI_RESET_METHODS_NUM ) +break ; + } +return rc; }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, rc; +u8 prio =PCI_RESET_METHODS_NUM ; +u8 reset_methods[PCI_RESET_METHODS_NUM ] = {0 }; -might_sleep (); +BUILD_BUG_ON (ARRAY_SIZE (pci_reset_fn_methods) !=PCI_RESET_METHODS_NUM ); - 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; +might_sleep (); -return pci_reset_bus_function (dev,1 ); +for (i =0 ; i <PCI_RESET_METHODS_NUM ; i++) { + rc = pci_reset_fn_methods[i].reset_fn (dev,1 ); +if (!rc) + reset_methods[i] = prio--; +else if (rc != -ENOTTY ) +break ; + } +memcpy (dev->reset_methods, reset_methods,sizeof (reset_methods)); }/**
drivers/pci/pci.h +7 -1
@@ -39,7 +39,7 @@ 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); +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);
@@ -612,6 +612,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 *,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
@@ -2403,9 +2403,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,8 @@ PCI_STATUS_SIG_TARGET_ABORT | \ PCI_STATUS_PARITY) +#define PCI_RESET_METHODS_NUM 5 +/* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded
@@ -506,6 +508,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_RESET_METHODS_NUM ];/* Reset methods ordered by priority */ };static inline struct pci_dev *pci_physfn (struct pci_dev *dev)
@@ -1219,6 +1225,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,void pcie_print_link_status (struct pci_dev *dev);int pcie_reset_flr (struct pci_dev *dev,int probe);int pcie_flr (struct pci_dev *dev); +bool pci_reset_supported (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);int pci_reset_function_locked (struct pci_dev *dev);
Signature · 1 line
2.31.1
PATCH v3 3/7 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. Deprecate 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 | 6 ++---- drivers/pci/pci.c | 6 +++--- drivers/pci/probe.c | 1 - drivers/pci/quirks.c | 2 +- include/linux/pci.h | 1 - 6 files changed, 7 insertions(+), 11 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 +2 -4
@@ -1334,7 +1334,7 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev)pcie_vpd_create_sysfs_dev_files (dev); -if (dev->reset_fn) { +if (pci_reset_supported (dev)) { retval =device_create_file (&dev->dev, &dev_attr_reset);if (retval) goto error;
@@ -1417,10 +1417,8 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)static void pci_remove_capabilities_sysfs (struct pci_dev *dev) {pcie_vpd_remove_sysfs_dev_files (dev); -if (dev->reset_fn) { +if (pci_reset_supported (dev))device_remove_file (&dev->dev, &dev_attr_reset); - dev->reset_fn =0 ; - } }/**
drivers/pci/pci.c +3 -3
@@ -5192,7 +5192,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);
@@ -5228,7 +5228,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);
@@ -5251,7 +5251,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
@@ -2404,7 +2404,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
@@ -5535,7 +5535,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))
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.31.1
PATCH v3 4/7 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 | 16 +++++ drivers/pci/pci-sysfs.c | 95 ++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-bus-pci +16 -0
@@ -121,6 +121,22 @@ 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. Reading this file will give names + of the device supported reset methods and their ordering. + 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 +92 -3
117 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 5/7 PCI: Add support for a function level reset based on _RST 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 ACPI binding information is available only after calling device_add(), so move pci_init_reset_methods() to end of the pci_device_add().
The default priority of the acpi reset is set to below device-specific and above hardware resets.
--- drivers/pci/pci.c | 30 ++++++++++++++++++++++++++++++ drivers/pci/probe.c | 2 +- include/linux/pci.h | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-)
drivers/pci/pci.c +30 -0
@@ -5076,6 +5076,35 @@ static void pci_dev_restore(struct pci_dev *dev) err_handler->reset_done (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. +*/ +static int pci_dev_acpi_reset (struct pci_dev *dev,int probe) +{ +#ifdef CONFIG_ACPI +acpi_handle handle =ACPI_HANDLE (&dev->dev); + +/* Return -ENOTTY if _RST method is not included in the dev context */ +if (!handle || !acpi_has_method (handle,"_RST" )) +return -ENOTTY ; + +/* Return 0 for probe phase indicating that we can reset this device */ +if (probe) +return 0 ; + +/* Invoke _RST() method to perform a function level reset */ +if (ACPI_FAILURE (acpi_evaluate_object (handle,"_RST" ,NULL ,NULL ))) { +pci_warn (dev,"Failed to reset the device\n" ); +return -EINVAL ; + } +return 0 ; +#else +return -ENOTTY ; +#endif +} +/* * The ordering for functions in pci_reset_fn_methods * is required for reset_methods byte array defined
@@ -5083,6 +5112,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/probe.c +1 -1
@@ -2403,7 +2403,6 @@ static void pci_init_capabilities(struct pci_dev *dev)pci_rcec_init (dev);/* Root Complex Event Collector */ pcie_report_downtraining (dev); -pci_init_reset_methods (dev); }/*
@@ -2494,6 +2493,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) dev->match_driver = false; ret =device_add (&dev->dev);WARN_ON (ret <0 ); +pci_init_reset_methods (dev); }struct pci_dev *pci_scan_single_device (struct pci_bus *bus,int devfn)
include/linux/pci.h +1 -1
@@ -49,7 +49,7 @@ PCI_STATUS_SIG_TARGET_ABORT | \ PCI_STATUS_PARITY) -#define PCI_RESET_METHODS_NUM 5 +#define PCI_RESET_METHODS_NUM 6/* * The PCI interface treats multi-function devices as independent
Signature · 1 line
2.31.1
PATCH v3 6/7 PCI: Enable NO_BUS_RESET quirk for Nvidia GPUs
In reply to Amey NarkhedeFrom: Shanker Donthineni <[email protected]>
On select platforms, some Nvidia GPU devices do not work with SBR. Triggering SBR would leave the device inoperable for the current system boot. It requires a system hard-reboot to get the GPU device back to normal operating condition post-SBR. For the affected devices, enable NO_BUS_RESET quirk to fix the issue.
This issue will be fixed in the next generation of hardware.
--- drivers/pci/quirks.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/pci/quirks.c +12 -0
@@ -3558,6 +3558,18 @@ static void quirk_no_bus_reset(struct pci_dev *dev) dev->dev_flags |=PCI_DEV_FLAGS_NO_BUS_RESET ; } +/* +* Some Nvidia GPU devices do not work with bus reset, SBR needs to be +* prevented for those affected devices. +*/ +static void quirk_nvidia_no_bus_reset (struct pci_dev *dev) +{ +if ((dev->device &0xffc0 ) ==0x2340 ) +quirk_no_bus_reset (dev); +} +DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_NVIDIA ,PCI_ANY_ID , + quirk_nvidia_no_bus_reset); +/* * Some Atheros AR9xxx and QCA988x chips do not behave after a bus reset. * The device will throw a Link Down error on AER-capable systems and
Signature · 1 line
2.31.1
PATCH v3 7/7 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 | 7 +- drivers/pci/pci.c | 85 +++++++++++++------ drivers/pci/pci.h | 8 +- drivers/pci/pcie/aer.c | 2 +- drivers/pci/quirks.c | 46 +++++++--- include/linux/pci.h | 8 +- include/linux/pci_hotplug.h | 2 +- 10 files changed, 112 insertions(+), 52 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 probe);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 +5 -2
@@ -834,14 +834,17 @@ 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,enum pci_reset_mode probe) {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 (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; + +if (probe ==PCI_RESET_PROBE )return 0 ;down_write (&ctrl->reset_lock);
drivers/pci/pci.c +58 -27
271 lines not on this page · raw message
drivers/pci/pci.h +4 -4
@@ -609,19 +609,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 probe); };struct pci_reset_fn_method { -int (*reset_fn)(struct pci_dev *,int probe); +int (*reset_fn)(struct pci_dev *,pci_reset_mode_t 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); +int pci_dev_specific_reset (struct pci_dev *dev,pci_reset_mode_t probe);#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 probe) {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 +33 -13
117 lines not on this page · raw message
include/linux/pci.h +7 -1
@@ -51,6 +51,12 @@#define PCI_RESET_METHODS_NUM 6 +typedef enum pci_reset_mode { +PCI_RESET_DO_RESET , +PCI_RESET_PROBE , +PCI_RESET_ACTION_MAX , +}pci_reset_mode_t ; +/* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded
@@ -1222,7 +1228,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 probe);int pcie_flr (struct pci_dev *dev);bool pci_reset_supported (struct pci_dev *dev);int __pci_reset_function_locked (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 probe); };/**
Signature · 1 line
2.31.1
Re: [PATCH v3 7/7] PCI: Change the type of probe argument in reset functions
Quoted 67 lines · On Wed, 26 May 2021 15:44:03 +0530 Amey Narkhede <[email protected]>…
Introduce a new enum
pci_reset_mode_tto 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 topci_reset_mode_tto make the intent clear. Add a new line in return statement ofpci_reset_bus_function.Suggested-by Alex Williamson <[email protected]>Suggested-by Krzysztof Wilczyński <[email protected]>Signed-off-by Amey Narkhede <[email protected]>--- 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 | 7 +- drivers/pci/pci.c | 85 +++++++++++++------ drivers/pci/pci.h | 8 +- drivers/pci/pcie/aer.c | 2 +- drivers/pci/quirks.c | 46 +++++++--- include/linux/pci.h | 8 +- include/linux/pci_hotplug.h | 2 +- 10 files changed, 112 insertions(+), 52 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 probe);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 +0
-0
drivers/pci/hotplug/pciehp_hpc.c void pcie_disable_interrupt(struct controller *ctrl) · line 837
Quoted 5 lines
drivers/pci/hotplug/pciehp_hpc.c +1
-1@@ -834,14 +834,17 @@ 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,enum pci_reset_mode probe)
This should use your typedef, pci_reset_mode_t. Is "probe" still the best name for this arg? The enum name suggests a "mode", the MAX entry suggests an "action", "probe" is but one mode/action.
Quoted 445 lines
drivers/pci/hotplug/pciehp_hpc.c +4
-1{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 (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; + +if (probe ==PCI_RESET_PROBE )return 0 ;down_write (&ctrl->reset_lock);drivers/pci/pci.c +58
-27@@ -4616,10 +4616,13 @@ EXPORT_SYMBOL_GPL(pcie_flr);* * Initiate a function level reset on @dev. */ -int pcie_reset_flr (struct pci_dev *dev,int probe) +int pcie_reset_flr (struct pci_dev *dev,pci_reset_mode_t probe) {u32 cap; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (dev->dev_flags &PCI_DEV_FLAGS_NO_FLR_RESET )return -ENOTTY ;@@ -4627,18 +4630,21 @@ int pcie_reset_flr(struct pci_dev *dev, int probe)if (!(cap &PCI_EXP_DEVCAP_FLR ))return -ENOTTY ; -if (probe) +if (probe ==PCI_RESET_PROBE )return 0 ;return pcie_flr (dev); }EXPORT_SYMBOL_GPL (pcie_reset_flr); -static int pci_af_flr (struct pci_dev *dev,int probe) +static int pci_af_flr (struct pci_dev *dev,pci_reset_mode_t probe) {int pos;u8 cap; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; + pos =pci_find_capability (dev,PCI_CAP_ID_AF );if (!pos)return -ENOTTY ;@@ -4650,7 +4656,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe)if (!(cap &PCI_AF_CAP_TP ) || !(cap &PCI_AF_CAP_FLR ))return -ENOTTY ; -if (probe) +if (probe ==PCI_RESET_PROBE )return 0 ;/* @@ -4693,10 +4699,13 @@ static int pci_af_flr(struct pci_dev *dev, int probe)* by default (i.e. unless the @dev's d3hot_delay field has a different value). * Moreover, only devices in D0 can be reset by this function. */ -static int pci_pm_reset (struct pci_dev *dev,int probe) +static int pci_pm_reset (struct pci_dev *dev,pci_reset_mode_t probe) {u16 csr; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (!dev->pm_cap || dev->dev_flags &PCI_DEV_FLAGS_NO_PM_RESET )return -ENOTTY ;@@ -4704,7 +4713,7 @@ static int pci_pm_reset(struct pci_dev *dev, int probe)if (csr &PCI_PM_CTRL_NO_SOFT_RESET )return -ENOTTY ; -if (probe) +if (probe ==PCI_RESET_PROBE )return 0 ;if (dev->current_state !=PCI_D0 )@@ -4953,10 +4962,13 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_bridge_secondary_bus_reset); -static int pci_parent_bus_reset (struct pci_dev *dev,int probe) +static int pci_parent_bus_reset (struct pci_dev *dev,pci_reset_mode_t probe) {struct pci_dev *pdev; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (pci_is_root_bus (dev->bus) || dev->subordinate || !dev->bus->self || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET )return -ENOTTY ;@@ -4965,16 +4977,19 @@ static int pci_parent_bus_reset(struct pci_dev *dev, int probe)if (pdev != dev)return -ENOTTY ; -if (probe) +if (probe ==PCI_RESET_PROBE )return 0 ;return pci_bridge_secondary_bus_reset (dev->bus->self); } -static int pci_reset_hotplug_slot (struct hotplug_slot *hotplug,int probe) +static int pci_reset_hotplug_slot (struct hotplug_slot *hotplug,pci_reset_mode_t probe) {int rc = -ENOTTY ; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (!hotplug || !try_module_get (hotplug->owner))return rc;@@ -4986,8 +5001,11 @@ static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, int probe)return rc; } -static int pci_dev_reset_slot_function (struct pci_dev *dev,int probe) +static int pci_dev_reset_slot_function (struct pci_dev *dev,pci_reset_mode_t probe) { +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (dev->multifunction || dev->subordinate || !dev->slot || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET )return -ENOTTY ;@@ -4995,12 +5013,16 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)return pci_reset_hotplug_slot (dev->slot->hotplug, probe); } -static int pci_reset_bus_function (struct pci_dev *dev,int probe) +static int pci_reset_bus_function (struct pci_dev *dev,pci_reset_mode_t probe) {int rc =pci_dev_reset_slot_function (dev, probe); +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (rc != -ENOTTY )return rc; +return pci_parent_bus_reset (dev, probe); }@@ -5081,17 +5103,20 @@ static void pci_dev_restore(struct pci_dev *dev)* @dev: device to reset * @probe: check if _RST method is included in the acpi_device context. */ -static int pci_dev_acpi_reset (struct pci_dev *dev,int probe) +static int pci_dev_acpi_reset (struct pci_dev *dev,pci_reset_mode_t probe) {#ifdef CONFIG_ACPI acpi_handle handle =ACPI_HANDLE (&dev->dev); +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +/* Return -ENOTTY if _RST method is not included in the dev context */ if (!handle || !acpi_has_method (handle,"_RST" ))return -ENOTTY ;/* Return 0 for probe phase indicating that we can reset this device */ -if (probe) +if (probe ==PCI_RESET_PROBE )return 0 ;/* Invoke _RST() method to perform a function level reset */ @@ -5157,7 +5182,7 @@ int __pci_reset_function_locked(struct pci_dev *dev)* other error, we're also finished: this indicates that further * reset mechanisms might be broken on the device. */ - rc = pci_reset_fn_methods[i].reset_fn (dev,0 ); + rc = pci_reset_fn_methods[i].reset_fn (dev,PCI_RESET_DO_RESET );if (rc != -ENOTTY )return rc;break ;@@ -5193,7 +5218,7 @@ void pci_init_reset_methods(struct pci_dev *dev)might_sleep ();for (i =0 ; i <PCI_RESET_METHODS_NUM ; i++) { - rc = pci_reset_fn_methods[i].reset_fn (dev,1 ); + rc = pci_reset_fn_methods[i].reset_fn (dev,PCI_RESET_PROBE );if (!rc) reset_methods[i] = prio--;else if (rc != -ENOTTY )@@ -5509,21 +5534,24 @@ static void pci_slot_restore_locked(struct pci_slot *slot) } } -static int pci_slot_reset (struct pci_slot *slot,int probe) +static int pci_slot_reset (struct pci_slot *slot,pci_reset_mode_t probe) {int rc; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (!slot || !pci_slot_resetable (slot))return -ENOTTY ; -if (!probe) +if (probe ==PCI_RESET_DO_RESET )pci_slot_lock (slot);might_sleep (); rc =pci_reset_hotplug_slot (slot->hotplug, probe); -if (!probe) +if (probe ==PCI_RESET_DO_RESET )pci_slot_unlock (slot);return rc;@@ -5537,7 +5565,7 @@ static int pci_slot_reset(struct pci_slot *slot, int probe)*/ int pci_probe_reset_slot (struct pci_slot *slot) { -return pci_slot_reset (slot,1 ); +return pci_slot_reset (slot,PCI_RESET_PROBE ); }EXPORT_SYMBOL_GPL (pci_probe_reset_slot);@@ -5560,14 +5588,14 @@ static int __pci_reset_slot(struct pci_slot *slot) {int rc; - rc =pci_slot_reset (slot,1 ); + rc =pci_slot_reset (slot,PCI_RESET_PROBE );if (rc)return rc;if (pci_slot_trylock (slot)) {pci_slot_save_and_disable_locked (slot);might_sleep (); - rc =pci_reset_hotplug_slot (slot->hotplug,0 ); + rc =pci_reset_hotplug_slot (slot->hotplug,PCI_RESET_DO_RESET );pci_slot_restore_locked (slot);pci_slot_unlock (slot); }else @@ -5576,14 +5604,17 @@ static int __pci_reset_slot(struct pci_slot *slot)return rc; } -static int pci_bus_reset (struct pci_bus *bus,int probe) +static int pci_bus_reset (struct pci_bus *bus,pci_reset_mode_t probe) {int ret; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +if (!bus->self || !pci_bus_resetable (bus))return -ENOTTY ; -if (probe) +if (probe ==PCI_RESET_PROBE )return 0 ;pci_bus_lock (bus);@@ -5622,14 +5653,14 @@ int pci_bus_error_reset(struct pci_dev *bridge) goto bus_reset;list_for_each_entry (slot, &bus->slots, list) -if (pci_slot_reset (slot,0 )) +if (pci_slot_reset (slot,PCI_RESET_DO_RESET )) goto bus_reset;mutex_unlock (&pci_slot_mutex);return 0 ; bus_reset:mutex_unlock (&pci_slot_mutex); -return pci_bus_reset (bridge->subordinate,0 ); +return pci_bus_reset (bridge->subordinate,PCI_RESET_DO_RESET ); }/** @@ -5640,7 +5671,7 @@ int pci_bus_error_reset(struct pci_dev *bridge)*/ int pci_probe_reset_bus (struct pci_bus *bus) { -return pci_bus_reset (bus,1 ); +return pci_bus_reset (bus,PCI_RESET_PROBE ); }EXPORT_SYMBOL_GPL (pci_probe_reset_bus);@@ -5654,7 +5685,7 @@ static int __pci_reset_bus(struct pci_bus *bus) {int rc; - rc =pci_bus_reset (bus,1 ); + rc =pci_bus_reset (bus,PCI_RESET_PROBE );if (rc)return rc;drivers/pci/pci.h +4
-4@@ -609,19 +609,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 probe); };struct pci_reset_fn_method { -int (*reset_fn)(struct pci_dev *,int probe); +int (*reset_fn)(struct pci_dev *,pci_reset_mode_t 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); +int pci_dev_specific_reset (struct pci_dev *dev,pci_reset_mode_t probe);#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 probe) {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
-9@@ -3693,8 +3693,11 @@ 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 probe) { +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +/* * http://www.intel.com/content/dam/doc/datasheet/82599-10-gbe-controller-datasheet.pdf * @@ -3703,7 +3706,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 (probe ==PCI_RESET_DO_RESET )pcie_flr (dev);return 0 ; }@@ -3715,13 +3718,16 @@ 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 probe) {void __iomem *mmio_base;unsigned long timeout;u32 val; -if (probe) +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; + +if (probe ==PCI_RESET_PROBE )return 0 ; mmio_base =pci_iomap (dev,0 ,0 );@@ -3758,11 +3764,14 @@ 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 probe) {u16 old_command;u16 msix_flags; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +/* * If this isn't a Chelsio T4-based device, return -ENOTTY indicating * that we have no device-specific reset method. @@ -3774,7 +3783,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 (probe ==PCI_RESET_PROBE )return 0 ;/* @@ -3836,17 +3845,20 @@ 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 probe) {void __iomem *bar;u16 cmd;u32 cfg; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ; +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 (probe ==PCI_RESET_PROBE )return 0 ; bar =pci_iomap (dev,0 ,NVME_REG_CC +sizeof (cfg));@@ -3910,11 +3922,16 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe)* device too soon after FLR. A 250ms delay after FLR has heuristically
drivers/pci/quirks.c static int nvme_disable_and_flr(struct pci_dev *dev, int probe) · line 3930
Quoted 10 lines
drivers/pci/quirks.c +5
-2* 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 probe) { -int ret =pcie_reset_flr (dev, probe); +int ret; + +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ;
pcie_reset_flr() handles this case, we could simply test (ret || probe == PCI_RESET_PROBE) below. In fact, that's probably what the code flow should have been regardless of this series.
Quoted 9 lines
drivers/pci/quirks.c +3
-1-if (probe) + ret =pcie_reset_flr (dev, probe); + +if (probe ==PCI_RESET_PROBE )return ret;msleep (250 );
drivers/pci/quirks.c static const struct pci_dev_reset_methods pci_dev_reset_methods[] = { · line 3966
Quoted 10 lines
drivers/pci/quirks.c +3
-1@@ -3941,10 +3958,13 @@ 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 probe) {const struct pci_dev_reset_methods *i; +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ;
If we test this here, none of the device specific resets modified above need a duplicate check. Thanks,
Alex
Quoted 43 lines
drivers/pci/quirks.c +1
-0+for (i = pci_dev_reset_methods; i->reset; i++) { if ((i->vendor == dev->vendor || i->vendor == (u16)PCI_ANY_ID) &&include/linux/pci.h +7
-1@@ -51,6 +51,12 @@#define PCI_RESET_METHODS_NUM 6 +typedef enum pci_reset_mode { +PCI_RESET_DO_RESET , +PCI_RESET_PROBE , +PCI_RESET_ACTION_MAX , +}pci_reset_mode_t ; +/* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded @@ -1222,7 +1228,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 probe);int pcie_flr (struct pci_dev *dev);bool pci_reset_supported (struct pci_dev *dev);int __pci_reset_function_locked (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 probe); };/**
Re: [PATCH v3 7/7] PCI: Change the type of probe argument in reset functions
Quoted 14 lines · Alex Williamson
Quoted 11 lines · On Wed, 26 May 2021 15:44:03 +0530 Amey Narkhede <[email protected]>…
Introduce a new enum
pci_reset_mode_tto 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 topci_reset_mode_tto make the intent clear. Add a new line in return statement ofpci_reset_bus_function.Suggested-by Alex Williamson <[email protected]>Suggested-by Krzysztof Wilczyński <[email protected]>Signed-off-by Amey Narkhede <[email protected]>---
[...]
Quoted 8 lines
drivers/pci/hotplug/pciehp_hpc.c void pcie_disable_interrupt(struct controller *ctrl) · line 837
Quoted 3 lines
*/
drivers/pci/hotplug/pciehp_hpc.c +1
-1-int pciehp_reset_slot (struct hotplug_slot *hotplug_slot,int probe) +int pciehp_reset_slot (struct hotplug_slot *hotplug_slot,enum pci_reset_mode probe)This should use your typedef,
pci_reset_mode_t. Is "probe" still the best name for this arg? The enum name suggests a "mode", the MAX entry suggests an "action", "probe" is but one mode/action.
My bad I missed this. Which sounds more intuitive to you "mode" or "action"? I update this in v4 to use consistent terminology once we everybody agrees on name.
[...]
Quoted 17 lines
drivers/pci/quirks.c static int nvme_disable_and_flr(struct pci_dev *dev, int probe) · line 3930
Quoted 12 lines
drivers/pci/quirks.c +5
-2@@ -3910,11 +3922,16 @@ 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 probe) { -int ret =pcie_reset_flr (dev, probe); +int ret; + +if (probe >=PCI_RESET_ACTION_MAX ) +return -EINVAL ;
pcie_reset_flr()handles this case, we could simply test (ret || probe ==PCI_RESET_PROBE) below. In fact, that's probably what the code flow should have been regardless of this series.
[...]
Quoted 5 lines
Quoted 5 lines
drivers/pci/quirks.c +1
-1-int pci_dev_specific_reset (struct pci_dev *dev,int probe) +int pci_dev_specific_reset (struct pci_dev *dev,pci_reset_mode_t probe) {const struct pci_dev_reset_methods *i;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (probe >= PCI_RESET_ACTION_MAX) + return -EINVAL;If we test this here, none of the device specific resets modified above need a duplicate check. Thanks,
Alex
I went ahead with excessive error checking in this patch. Will update in v4.
Thanks,
Amey