2021-07-05 14:25:17

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v9 0/8] 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 v9:
- Renamed has_flr bitfield to has_pcie_flr and restored
use of PCI_DEV_FLAGS_NO_FLR_RESET in quirk_no_flr()
- Cleaned up sysfs code

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 | 107 ++++++++-
drivers/pci/pci.c | 215 ++++++++++--------
drivers/pci/pci.h | 23 +-
drivers/pci/pcie/aer.c | 12 +-
drivers/pci/probe.c | 17 +-
drivers/pci/quirks.c | 42 ++--
drivers/pci/remove.c | 1 -
include/linux/pci.h | 17 +-
include/linux/pci_hotplug.h | 2 +-
15 files changed, 361 insertions(+), 144 deletions(-)

--
2.32.0


2021-07-05 14:26:51

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v9 7/8] PCI: Add support for ACPI _RST reset method

From: 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.

Signed-off-by: Shanker Donthineni <[email protected]>
Suggested-by: Alex Williamson <[email protected]>
Reviewed-by: Sinan Kaya <[email protected]>
---
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(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index dae021322..b6de71d15 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d5c16492c..1e64dbd3e 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5115,6 +5115,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" },
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 990b73e90..2c12017ed 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -705,7 +705,13 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL
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);
+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)
{
diff --git a/include/linux/pci.h b/include/linux/pci.h
index f34563831..c3b0d771c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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
--
2.32.0

2021-07-05 14:27:26

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v9 8/8] PCI: Change the type of probe argument in reset functions

Introduce 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().

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 | 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(-)

diff --git a/drivers/crypto/cavium/nitrox/nitrox_main.c b/drivers/crypto/cavium/nitrox/nitrox_main.c
index 15d6c8452..f97fa8e99 100644
--- a/drivers/crypto/cavium/nitrox/nitrox_main.c
+++ b/drivers/crypto/cavium/nitrox/nitrox_main.c
@@ -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);

diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
index 336d149ee..6e666be69 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
@@ -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);
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index 4fd200d8b..87da03adc 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -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);
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index fb3840e22..24b3c8787 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -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);
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index b6de71d15..a92ed574a 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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))) {
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 8a740e211..dcf19f6d6 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1393,7 +1393,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;
}
@@ -1405,7 +1406,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");

set_reset_methods:
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 1e64dbd3e..60204cee6 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4650,30 +4650,36 @@ 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.
+ * @mode: If PCI_RESET_PROBE, 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)
+int pcie_reset_flr(struct pci_dev *dev, pci_reset_mode_t mode)
{
+ if (mode >= PCI_RESET_MODE_MAX)
+ return -EINVAL;
+
if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET)
return -ENOTTY;

if (!dev->has_pcie_flr)
return -ENOTTY;

- if (probe)
+ if (mode == 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 mode)
{
int pos;
u8 cap;

+ if (mode >= PCI_RESET_MODE_MAX)
+ return -EINVAL;
+
pos = pci_find_capability(dev, PCI_CAP_ID_AF);
if (!pos)
return -ENOTTY;
@@ -4685,7 +4691,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 (mode == PCI_RESET_PROBE)
return 0;

/*
@@ -4716,7 +4722,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe)
/**
* pci_pm_reset - Put device into PCI_D3 and back into PCI_D0.
* @dev: Device to reset.
- * @probe: If set, only check if the device can be reset this way.
+ * @mode: If PCI_RESET_PROBE, only check if the device can be reset this way.
*
* If @dev supports native PCI PM and its PCI_PM_CTRL_NO_SOFT_RESET flag is
* unset, it will be reinitialized internally when going from PCI_D3hot to
@@ -4728,10 +4734,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 mode)
{
u16 csr;

+ if (mode >= PCI_RESET_MODE_MAX)
+ return -EINVAL;
+
if (!dev->pm_cap || dev->dev_flags & PCI_DEV_FLAGS_NO_PM_RESET)
return -ENOTTY;

@@ -4739,7 +4748,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 (mode == PCI_RESET_PROBE)
return 0;

if (dev->current_state != PCI_D0)
@@ -4988,10 +4997,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 mode)
{
struct pci_dev *pdev;

+ if (mode >= PCI_RESET_MODE_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;
@@ -5000,44 +5012,47 @@ static int pci_parent_bus_reset(struct pci_dev *dev, int probe)
if (pdev != dev)
return -ENOTTY;

- if (probe)
+ if (mode == 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 mode)
{
int rc = -ENOTTY;

+ if (mode >= PCI_RESET_MODE_MAX)
+ return -EINVAL;
+
if (!hotplug || !try_module_get(hotplug->owner))
return rc;

if (hotplug->ops->reset_slot)
- rc = hotplug->ops->reset_slot(hotplug, probe);
+ rc = hotplug->ops->reset_slot(hotplug, mode);

module_put(hotplug->owner);

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 mode)
{
if (dev->multifunction || dev->subordinate || !dev->slot ||
dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
return -ENOTTY;

- return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
+ return pci_reset_hotplug_slot(dev->slot->hotplug, mode);
}

-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 mode)
{
int rc;

- rc = pci_dev_reset_slot_function(dev, probe);
+ rc = pci_dev_reset_slot_function(dev, mode);
if (rc != -ENOTTY)
return rc;
- return pci_parent_bus_reset(dev, probe);
+ return pci_parent_bus_reset(dev, mode);
}

static void pci_dev_lock(struct pci_dev *dev)
@@ -5157,7 +5172,7 @@ int __pci_reset_function_locked(struct pci_dev *dev)
* mechanisms might be broken on the device.
*/
for (i = 0; i < PCI_NUM_RESET_METHODS && (m = dev->reset_methods[i]); i++) {
- rc = pci_reset_fn_methods[m].reset_fn(dev, 0);
+ rc = pci_reset_fn_methods[m].reset_fn(dev, PCI_RESET_DO_RESET);
if (!rc)
return 0;
if (rc != -ENOTTY)
@@ -5192,7 +5207,7 @@ void pci_init_reset_methods(struct pci_dev *dev)
might_sleep();

for (i = 1; i < PCI_NUM_RESET_METHODS; 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[n++] = i;
else if (rc != -ENOTTY)
@@ -5509,21 +5524,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 mode)
{
int rc;

+ if (mode >= PCI_RESET_MODE_MAX)
+ return -EINVAL;
+
if (!slot || !pci_slot_resetable(slot))
return -ENOTTY;

- if (!probe)
+ if (mode != PCI_RESET_PROBE)
pci_slot_lock(slot);

might_sleep();

- rc = pci_reset_hotplug_slot(slot->hotplug, probe);
+ rc = pci_reset_hotplug_slot(slot->hotplug, mode);

- if (!probe)
+ if (mode != PCI_RESET_PROBE)
pci_slot_unlock(slot);

return rc;
@@ -5537,7 +5555,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 +5578,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 +5594,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 mode)
{
int ret;

+ if (mode >= PCI_RESET_MODE_MAX)
+ return -EINVAL;
+
if (!bus->self || !pci_bus_resetable(bus))
return -ENOTTY;

- if (probe)
+ if (mode == PCI_RESET_PROBE)
return 0;

pci_bus_lock(bus);
@@ -5622,14 +5643,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 +5661,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 +5675,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;

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 2c12017ed..06be9e6fa 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -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 -EINVAL
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);
-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;
}
diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index 98077595a..cfa7a1775 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -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
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index e86cf4a3b..e7f15fc02 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -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;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c3b0d771c..0d650c873 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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
@@ -1232,7 +1238,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);
diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
index b482e42d7..9e8da46e7 100644
--- a/include/linux/pci_hotplug.h
+++ b/include/linux/pci_hotplug.h
@@ -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

2021-07-05 23:44:52

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v9 8/8] PCI: Change the type of probe argument in reset functions

Hi Amey,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on pci/next]
[cannot apply to pm/linux-next cryptodev/master crypto/master linus/master v5.13 next-20210701]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Amey-Narkhede/Expose-and-manage-PCI-device-reset/20210705-222358
base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/4866dd22881441f63dc57f682b3acbc539c83fe2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Amey-Narkhede/Expose-and-manage-PCI-device-reset/20210705-222358
git checkout 4866dd22881441f63dc57f682b3acbc539c83fe2
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> drivers/pci/hotplug/pnv_php.c:603:17: error: initialization of 'int (*)(struct hotplug_slot *, pci_reset_mode_t)' {aka 'int (*)(struct hotplug_slot *, enum pci_reset_mode)'} from incompatible pointer type 'int (*)(struct hotplug_slot *, int)' [-Werror=incompatible-pointer-types]
603 | .reset_slot = pnv_php_reset_slot,
| ^~~~~~~~~~~~~~~~~~
drivers/pci/hotplug/pnv_php.c:603:17: note: (near initialization for 'php_slot_ops.reset_slot')
cc1: some warnings being treated as errors


vim +603 drivers/pci/hotplug/pnv_php.c

66725152fb9f17 Gavin Shan 2016-05-20 595
81c4b5bf30de01 Lukas Wunner 2018-09-08 596 static const struct hotplug_slot_ops php_slot_ops = {
66725152fb9f17 Gavin Shan 2016-05-20 597 .get_power_status = pnv_php_get_power_state,
66725152fb9f17 Gavin Shan 2016-05-20 598 .get_adapter_status = pnv_php_get_adapter_state,
a7da21613c4efc Lukas Wunner 2018-09-08 599 .get_attention_status = pnv_php_get_attention_state,
66725152fb9f17 Gavin Shan 2016-05-20 600 .set_attention_status = pnv_php_set_attention_state,
66725152fb9f17 Gavin Shan 2016-05-20 601 .enable_slot = pnv_php_enable_slot,
66725152fb9f17 Gavin Shan 2016-05-20 602 .disable_slot = pnv_php_disable_slot,
7fd1fe4e4811f5 Oliver O'Halloran 2019-09-03 @603 .reset_slot = pnv_php_reset_slot,
66725152fb9f17 Gavin Shan 2016-05-20 604 };
66725152fb9f17 Gavin Shan 2016-05-20 605

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (3.04 kB)
.config.gz (71.67 kB)
Download all attachments