2021-06-08 05:52:33

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v7 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 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: Setup ACPI_COMPANION early
PCI: Add support for ACPI _RST reset 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 | 4 +-
drivers/pci/pci-acpi.c | 39 ++-
drivers/pci/pci-sysfs.c | 120 ++++++++-
drivers/pci/pci.c | 238 +++++++++++-------
drivers/pci/pci.h | 22 +-
drivers/pci/pcie/aer.c | 12 +-
drivers/pci/probe.c | 6 +-
drivers/pci/quirks.c | 54 ++--
drivers/pci/remove.c | 1 -
include/linux/pci.h | 16 +-
include/linux/pci_hotplug.h | 2 +-
15 files changed, 393 insertions(+), 145 deletions(-)

--
2.31.1


2021-06-08 05:53:19

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v7 6/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 eaddbf701..40dd24cd3 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 2302aa421..2e7efd7e7 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5121,6 +5121,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 d22da6d3c..e9cfb7cd6 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -704,7 +704,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 6e9bc4f9c..a7f063da2 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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
--
2.31.1

2021-06-08 05:53:19

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v7 2/8] PCI: Add new array for keeping track of ordering of reset methods

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

Reviewed-by: Alex Williamson <[email protected]>
Reviewed-by: Raphael Norwitz <[email protected]>
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 | 108 ++++++++++++++++++++++++++------------------
drivers/pci/pci.h | 8 +++-
drivers/pci/probe.c | 5 +-
include/linux/pci.h | 7 +++
4 files changed, 81 insertions(+), 47 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 3bf36924c..39a9ea8bb 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -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
@@ -5107,6 +5115,18 @@ 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.
@@ -5129,65 +5149,67 @@ 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));
}

/**
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 37c913bbc..13ec6bd6f 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -33,7 +33,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);

@@ -606,6 +606,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
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 3a62d09b8..8cf532681 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2404,9 +2404,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);
}

/*
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 20b90c205..0955246f8 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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
@@ -505,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_RESET_METHODS_NUM]; /* Reset methods ordered by priority */
};

static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
@@ -1227,6 +1233,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);
--
2.31.1

2021-06-08 05:53:19

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v7 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.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 +-
11 files changed, 101 insertions(+), 65 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 40dd24cd3..9de334457 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.c b/drivers/pci/pci.c
index 2e7efd7e7..e28611d7c 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4650,14 +4650,17 @@ 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)
{
u32 cap;

+ if (mode >= PCI_RESET_MODE_MAX)
+ return -EINVAL;
+
if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET)
return -ENOTTY;

@@ -4665,18 +4668,21 @@ int pcie_reset_flr(struct pci_dev *dev, int probe)
if (!(cap & PCI_EXP_DEVCAP_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;
@@ -4688,7 +4694,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;

/*
@@ -4719,7 +4725,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
@@ -4731,10 +4737,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;

@@ -4742,7 +4751,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)
@@ -4991,10 +5000,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;
@@ -5003,44 +5015,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)
@@ -5168,7 +5183,7 @@ int __pci_reset_function_locked(struct pci_dev *dev)
* 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;
@@ -5204,7 +5219,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)
@@ -5520,21 +5535,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;
@@ -5548,7 +5566,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);

@@ -5571,14 +5589,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
@@ -5587,14 +5605,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);
@@ -5633,14 +5654,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);
}

/**
@@ -5651,7 +5672,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);

@@ -5665,7 +5686,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 e9cfb7cd6..9787700f8 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -603,19 +603,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;
}
@@ -704,9 +704,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 45a8c3caa..60fd101ac 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3681,7 +3681,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
@@ -3691,7 +3691,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;
}
@@ -3703,13 +3703,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);
@@ -3746,7 +3746,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;
@@ -3762,7 +3762,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;

/*
@@ -3824,17 +3824,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));
@@ -3898,11 +3898,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);
@@ -3918,13 +3920,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);
@@ -3995,16 +3997,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 a7f063da2..c46df52e6 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -51,6 +51,12 @@

#define PCI_RESET_METHODS_NUM 6

+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);
bool pci_reset_supported(struct pci_dev *dev);
int __pci_reset_function_locked(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.31.1

2021-06-08 05:54:02

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v7 3/8] PCI: Remove reset_fn field from pci_dev

reset_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.

Reviewed-by: Alex Williamson <[email protected]>
Reviewed-by: Raphael Norwitz <[email protected]>
Co-developed-by: Alex Williamson <[email protected]>
Signed-off-by: Alex Williamson <[email protected]>
Signed-off-by: Amey Narkhede <[email protected]>
---
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(-)

diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
index 516f166ce..336d149ee 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 (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);
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index beb8d1f4f..316f70c3e 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -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;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 39a9ea8bb..2302aa421 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5232,7 +5232,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);
@@ -5268,7 +5268,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);
@@ -5291,7 +5291,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))
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 8cf532681..90fd4f61f 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2405,7 +2405,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);
}

/*
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index f977ba79a..e86cf4a3b 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -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))
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index dd12c2fcc..4c54c7505 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -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);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 0955246f8..6e9bc4f9c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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 */
--
2.31.1

2021-06-08 05:54:34

by Amey Narkhede

[permalink] [raw]
Subject: [PATCH v7 5/8] PCI: Setup ACPI_COMPANION early

From: Shanker Donthineni <[email protected]>

Currently, the ACPI_COMPANION is not available until device_add().
The software features which have dependency on ACPI fwnode properties
and needs to be handled before device_add() will not work. One use
case, software has to check the existence of _RST method to support
ACPI based reset mechanism.

This patch adds a new function pci_set_acpi_fwnode() for setting the
ACPI_COMPANION, same code which is available in acpi_pci_bridge_d3().

Call pci_set_acpi_fwnode() from pci_scan_device() to fix the issue.

Signed-off-by: Shanker Donthineni <[email protected]>
---
drivers/pci/pci-acpi.c | 12 ++++++++----
drivers/pci/pci.h | 2 ++
drivers/pci/probe.c | 2 ++
3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 36bc23e21..eaddbf701 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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;
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 13ec6bd6f..d22da6d3c 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -703,7 +703,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;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 90fd4f61f..dfefa5ed0 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2359,6 +2359,8 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
return NULL;
}

+ pci_set_acpi_fwnode(dev);
+
return dev;
}

--
2.31.1

Subject: Re: [PATCH v7 0/8] Expose and manage PCI device reset

On 08.06.21 07:48, Amey Narkhede wrote:

Hi,

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

Since I've got a current use case for that - could you perhaps tell more
about the whole pci device reset mechanisms ?

In my case I've got a board that wires reset lines to the soc's gpios.
Not sure how exactly to qualify this, but I guess it would count as a
bus wide reset.

Now the big question for me is how to implement that in a board specific
platform driver (which already does setup of gpios and other attached
devices), so we can reset the card in slot X in a generic way.

Any help highly appreciated.


--mtx

--
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert
werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren
GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
[email protected] -- +49-151-27565287

2021-06-08 15:49:38

by Amey Narkhede

[permalink] [raw]
Subject: Re: [PATCH v7 0/8] Expose and manage PCI device reset

On 21/06/08 12:05PM, Enrico Weigelt, metux IT consult wrote:
> On 08.06.21 07:48, Amey Narkhede wrote:
>
> Hi,
>
> > 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.
>
> Since I've got a current use case for that - could you perhaps tell more
> about the whole pci device reset mechanisms ?
>
> In my case I've got a board that wires reset lines to the soc's gpios.
> Not sure how exactly to qualify this, but I guess it would count as a
> bus wide reset.
>
> Now the big question for me is how to implement that in a board specific
> platform driver (which already does setup of gpios and other attached
> devices), so we can reset the card in slot X in a generic way.
>
> Any help highly appreciated.
>
>
> --mtx
>
In case of bus reset(pci_reset_secondary_bus()), it uses bridge control
register to assert reset on bus so I think it should out of the box but
not 100% sure about it.

Thanks,
Amey

2021-06-09 21:42:58

by Raphael Norwitz

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

On Tue, Jun 08, 2021 at 11:18:57AM +0530, Amey Narkhede wrote:
> 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]>

Reviewed-by: Raphael Norwitz <[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.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 +-
> 11 files changed, 101 insertions(+), 65 deletions(-)

2021-06-10 20:18:42

by Shanker Donthineni

[permalink] [raw]
Subject: Re: [PATCH v7 2/8] PCI: Add new array for keeping track of ordering of reset methods



On 6/8/21 12:48 AM, Amey Narkhede wrote:
> Introduce 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.
>
> Reviewed-by: Alex Williamson <[email protected]>
> Reviewed-by: Raphael Norwitz <[email protected]>
> Co-developed-by: Alex Williamson <[email protected]>
> Signed-off-by: Alex Williamson <[email protected]>
> Signed-off-by: Amey Narkhede <[email protected]>

Tested-by: Shanker Donthineni <[email protected]>

2021-06-10 20:20:01

by Shanker Donthineni

[permalink] [raw]
Subject: Re: [PATCH v7 3/8] PCI: Remove reset_fn field from pci_dev



On 6/8/21 12:48 AM, Amey Narkhede wrote:
> reset_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.
>
> Reviewed-by: Alex Williamson <[email protected]>
> Reviewed-by: Raphael Norwitz <[email protected]>
> Co-developed-by: Alex Williamson <[email protected]>
> Signed-off-by: Alex Williamson <[email protected]>
> Signed-off-by: Amey Narkhede <[email protected]>

Tested-by: Shanker Donthineni <[email protected]>

2021-06-18 02:54:06

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v7 2/8] PCI: Add new array for keeping track of ordering of reset methods

"Add new" in subject and below is slightly redundant.

On Tue, Jun 08, 2021 at 11:18:51AM +0530, Amey Narkhede wrote:
> Introduce 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.
>
> Reviewed-by: Alex Williamson <[email protected]>
> Reviewed-by: Raphael Norwitz <[email protected]>
> 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 | 108 ++++++++++++++++++++++++++------------------
> drivers/pci/pci.h | 8 +++-
> drivers/pci/probe.c | 5 +-
> include/linux/pci.h | 7 +++
> 4 files changed, 81 insertions(+), 47 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 3bf36924c..39a9ea8bb 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -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);

memcmp() doesn't actually return a bool. Either just return int
and rely on the C "anything non-zero is true, zero is false" or
convert the memcmp result to bool, i.e., something like:

if (memcmp(...) == 0)
return true;
return false;

> +}
> +
> #ifdef CONFIG_PCI_DOMAINS
> int pci_domains_supported = 1;
> #endif
> @@ -5107,6 +5115,18 @@ 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.

I'm not quite sure what this comment is telling me. What breaks if I
change the order? If I add a new method, how do I know where to put
it?

By reading the code, I infer that:

- Each dev has dev->reset_methods[PCI_RESET_METHODS_NUM]

- dev->reset_methods[i] corresponds to pci_reset_fn_methods[i]

- dev->reset_methods[i] == 0 means dev doesn't support that method

- Otherwise, dev->reset_methods[i] is a value in the range of
[1, PCI_RESET_METHODS_NUM], and the higher the number, the higher
the reset method priority

- The order in pci_reset_fn_methods[] determines the initial
priority via pci_init_reset_methods(), but the priority can be
changed via sysfs

> + */
> +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.
> @@ -5129,65 +5149,67 @@ 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;

Maybe leave the comment outside the loop where it used to be so the
text lines are longer and it's easier to read.

> + break;
> + }
> + }
> + if (i == PCI_RESET_METHODS_NUM)
> + break;
> + }
> + return rc;

I wonder if this would be easier if dev->reset_methods[] contained
indices into pci_reset_fn_methods[], highest priority first, with the
priority being determined when dev->reset_methods[] is updated. For
example:

const struct pci_reset_fn_method pci_reset_fn_methods[] = {
{ }, # 0
{ &pci_dev_specific_reset, .name = "device_specific" }, # 1
{ &pci_dev_acpi_reset, .name = "acpi" }, # 2
{ &pcie_reset_flr, .name = "flr" }, # 3
{ &pci_af_flr, .name = "af_flr" }, # 4
{ &pci_pm_reset, .name = "pm" }, # 5
{ &pci_reset_bus_function, .name = "bus" }, # 6
};

dev->reset_methods[] = [1, 2, 3, 4, 5, 6]
means all reset methods are supported, in the default priority
order

dev->reset_methods[] = [1, 0, 0, 0, 0, 0]
means only pci_dev_specific_reset is supported

dev->reset_methods[] = [3, 5, 0, 0, 0, 0]
means pcie_reset_flr and pci_pm_reset are supported, in that
priority order

Then we wouldn't need the nested loop and the return value would be
easier to analyze:

for (i = 0; i < PCI_RESET_METHODS_NUM && (m = dev->reset_methods[i]); i++) {
rc = pci_reset_fn_methods[m].reset_fn(dev, 0);
if (rc == 0)
return 0;
if (rc != -ENOTTY)
return rc;
}
return -ENOTTY;

pci_init_reset_methods() would be something like:

n = 0;
for (i = 1; i < PCI_RESET_METHODS_NUM; i++) {
rc = pci_reset_fn_methods[i].reset_fn(dev, 1);
if (!rc)
dev->reset_methods[n++] = i;
if (rc != -ENOTTY)
return;
}

> }
> 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));
> }
>
> /**
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 37c913bbc..13ec6bd6f 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -33,7 +33,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);
>
> @@ -606,6 +606,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
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 3a62d09b8..8cf532681 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -2404,9 +2404,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);
> }
>
> /*
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 20b90c205..0955246f8 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -49,6 +49,8 @@
> PCI_STATUS_SIG_TARGET_ABORT | \
> PCI_STATUS_PARITY)
>
> +#define PCI_RESET_METHODS_NUM 5

I'm pretty sure this needs to be kept in sync with something, maybe
ARRAY_SIZE(pci_reset_fn_methods)? We need some mechanism to enforce
this, or at the very least, a comment. Oh, I see you have a
BUILD_BUG_ON() in pci_init_reset_methods(). That's good, but a
comment here would help, too.

This name should be something like "PCI_RESET_METHODS" or
"PCI_NUM_RESET_METHODS". Putting "_NUM" at the end makes it sounds
like we're referring to one specific method.

> /*
> * The PCI interface treats multi-function devices as independent
> * devices. The slot/function address of each device is encoded
> @@ -505,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_RESET_METHODS_NUM]; /* Reset methods ordered by priority */
> };
>
> static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
> @@ -1227,6 +1233,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);

This function isn't used outside drivers/pci/, so I'd rather have the
prototype in drivers/pci/pci.h.

> 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);
> --
> 2.31.1
>

2021-06-19 02:17:20

by Amey Narkhede

[permalink] [raw]
Subject: Re: [PATCH v7 2/8] PCI: Add new array for keeping track of ordering of reset methods

On 21/06/17 06:13PM, Bjorn Helgaas wrote:
> "Add new" in subject and below is slightly redundant.
>
> On Tue, Jun 08, 2021 at 11:18:51AM +0530, Amey Narkhede wrote:
> > Introduce 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.
> >
> > Reviewed-by: Alex Williamson <[email protected]>
> > Reviewed-by: Raphael Norwitz <[email protected]>
> > 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 | 108 ++++++++++++++++++++++++++------------------
> > drivers/pci/pci.h | 8 +++-
> > drivers/pci/probe.c | 5 +-
> > include/linux/pci.h | 7 +++
> > 4 files changed, 81 insertions(+), 47 deletions(-)
> >
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index 3bf36924c..39a9ea8bb 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -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);
>
> memcmp() doesn't actually return a bool. Either just return int
> and rely on the C "anything non-zero is true, zero is false" or
> convert the memcmp result to bool, i.e., something like:
>
> if (memcmp(...) == 0)
> return true;
> return false;
>
> > +}
> > +
> > #ifdef CONFIG_PCI_DOMAINS
> > int pci_domains_supported = 1;
> > #endif
> > @@ -5107,6 +5115,18 @@ 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.
>
> I'm not quite sure what this comment is telling me. What breaks if I
> change the order? If I add a new method, how do I know where to put
> it?
>
> By reading the code, I infer that:
>
> - Each dev has dev->reset_methods[PCI_RESET_METHODS_NUM]
>
> - dev->reset_methods[i] corresponds to pci_reset_fn_methods[i]
>
> - dev->reset_methods[i] == 0 means dev doesn't support that method
>
> - Otherwise, dev->reset_methods[i] is a value in the range of
> [1, PCI_RESET_METHODS_NUM], and the higher the number, the higher
> the reset method priority
>
> - The order in pci_reset_fn_methods[] determines the initial
> priority via pci_init_reset_methods(), but the priority can be
> changed via sysfs
>
Correct. I agree the comment is not clear. Adding new reset method won't break
anything unless default order is changed and user has some assumptions from
previous versions of kernel.
> > + */
> > +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.
> > @@ -5129,65 +5149,67 @@ 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;
>
> Maybe leave the comment outside the loop where it used to be so the
> text lines are longer and it's easier to read.
>
> > + break;
> > + }
> > + }
> > + if (i == PCI_RESET_METHODS_NUM)
> > + break;
> > + }
> > + return rc;
>
> I wonder if this would be easier if dev->reset_methods[] contained
> indices into pci_reset_fn_methods[], highest priority first, with the
> priority being determined when dev->reset_methods[] is updated. For
> example:
>
> const struct pci_reset_fn_method pci_reset_fn_methods[] = {
> { }, # 0
> { &pci_dev_specific_reset, .name = "device_specific" }, # 1
> { &pci_dev_acpi_reset, .name = "acpi" }, # 2
> { &pcie_reset_flr, .name = "flr" }, # 3
> { &pci_af_flr, .name = "af_flr" }, # 4
> { &pci_pm_reset, .name = "pm" }, # 5
> { &pci_reset_bus_function, .name = "bus" }, # 6
> };
>
> dev->reset_methods[] = [1, 2, 3, 4, 5, 6]
> means all reset methods are supported, in the default priority
> order
>
> dev->reset_methods[] = [1, 0, 0, 0, 0, 0]
> means only pci_dev_specific_reset is supported
>
> dev->reset_methods[] = [3, 5, 0, 0, 0, 0]
> means pcie_reset_flr and pci_pm_reset are supported, in that
> priority order
>
> Then we wouldn't need the nested loop and the return value would be
> easier to analyze:
>
> for (i = 0; i < PCI_RESET_METHODS_NUM && (m = dev->reset_methods[i]); i++) {
> rc = pci_reset_fn_methods[m].reset_fn(dev, 0);
> if (rc == 0)
> return 0;
> if (rc != -ENOTTY)
> return rc;
> }
> return -ENOTTY;
>
> pci_init_reset_methods() would be something like:
>
> n = 0;
> for (i = 1; i < PCI_RESET_METHODS_NUM; i++) {
> rc = pci_reset_fn_methods[i].reset_fn(dev, 1);
> if (!rc)
> dev->reset_methods[n++] = i;
> if (rc != -ENOTTY)
> return;
> }
>
I had similar idea initially but couldn't put it in words nicely
thanks for this. I'll update this.
[...]

Thanks,
Amey

2021-06-21 15:04:53

by Shanker Donthineni

[permalink] [raw]
Subject: Re: [PATCH v7 2/8] PCI: Add new array for keeping track of ordering of reset methods

Hi Bjorn,

On 6/18/21 12:22 PM, Amey Narkhede wrote:
> I wonder if this would be easier if dev->reset_methods[] contained
> indices into pci_reset_fn_methods[], highest priority first, with the
> priority being determined when dev->reset_methods[] is updated. For
> example:
>
> const struct pci_reset_fn_method pci_reset_fn_methods[] = {
> { }, # 0
> { &pci_dev_specific_reset, .name = "device_specific" }, # 1
> { &pci_dev_acpi_reset, .name = "acpi" }, # 2
> { &pcie_reset_flr, .name = "flr" }, # 3
> { &pci_af_flr, .name = "af_flr" }, # 4
> { &pci_pm_reset, .name = "pm" }, # 5
> { &pci_reset_bus_function, .name = "bus" }, # 6
> };
>
> dev->reset_methods[] = [1, 2, 3, 4, 5, 6]
> means all reset methods are supported, in the default priority
> order
>
> dev->reset_methods[] = [1, 0, 0, 0, 0, 0]
> means only pci_dev_specific_reset is supported
>
> dev->reset_methods[] = [3, 5, 0, 0, 0, 0]
> means pcie_reset_flr and pci_pm_reset are supported, in that
> priority order
What about keeping two bitmap fields 'resets_supported' and 'resets_enabled' in
pci_dev object and mange it through sysfs and probe helper function. We can avoid
two loops multiple paces and takes only 2Bytes of memory to keep track resets.

resets_supported  ---> initialized during pci_dev setup
resets_enabled ---> Exposed to userspace through sysfs by default set to resets_supported

include/linux/pci.h:
------------------------
/* Different types of PCI resets possible, lower number is higher priority */
#define PCI_RESET_METHOD_DEVSPEC     0
#define PCI_RESET_METHOD_ACPI            1
#define PCI_RESET_METHOD_FLR              2
#define PCI_RESET_METHOD_Af_FLR         3
#define PCI_RESET_METHOD_PM               4
#define PCI_RESET_METHOD_BUS             5
#define PCI_RESET_METHOD_MAX            6

struct pci_dev {
    ...
        u8              resets_supported;
        u8              resets_enabled;
};

static inline bool pci_reset_supported(struct pci_dev *dev)
{
        return !!(dev->resets_supported);
}


drivers/pci/pci.c:
--------------------
const struct pci_reset_fn_method pci_reset_fn_methods[PCI_RESET_METHOD_MAX] = {
        [PCI_RESET_METHOD_DEVSPEC] = { &pci_dev_specific_reset,
                                                                   .name = "device_specific" },
        [PCI_RESET_METHOD_ACPI] = { &pci_dev_acpi_reset, .name = "acpi" },
        [PCI_RESET_METHOD_FLR] = { &pcie_reset_flr, .name = "flr" },
        [PCI_RESET_METHOD_Af_FLR] = { &pci_af_flr, .name = "af_flr" },
        [PCI_RESET_METHOD_PM] = { &pci_pm_reset, .name = "pm" },
        [PCI_RESET_METHOD_BUS] = { &pci_reset_bus_function, .name = "bus" }
};


void pci_init_reset_methods(struct pci_dev *dev)
{
        int i, rc;

        BUILD_BUG_ON(ARRAY_SIZE(pci_reset_fn_methods) != PCI_RESET_METHOD_MAX);
        might_sleep();

        for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
                rc = pci_reset_fn_methods[i].reset_fn(dev, PCI_RESET_PROBE);
                if (!rc)
                        dev->resets_supported |= BIT(i);
                else if (rc != -ENOTTY)
                        break;
        }
        dev->resets_enabled = dev->resets_supported;
}

int __pci_reset_function_locked(struct pci_dev *dev)
{
        int i, rc = -ENOTTY;

        might_sleep();

        for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
                if (dev->resets_enabled & BIT(i)) {
                        rc = pci_reset_fn_methods[i].reset_fn(dev, 0);
                        if (rc != -ENOTTY)
                                return rc;
                }
        }

        if (rc == -ENOTTY)
                pci_warn(dev, "No reset happened reason %s\n",
                         !!dev->resets_supported ?
                         "disabled by user" : "not supported");

        return rc;
}

drivers/pci/pci-sysfs.c
----------------------------
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);
        u8 resets_enabled = 0;
...
        if (sysfs_streq(options, "default")) {
                pdev->resets_enabled = pdev->resets_supported;
                goto set_reset_methods;
        }

        while ((name = strsep(&options, ",")) != NULL) {
                if (sysfs_streq(name, ""))
                        continue;
                name = strim(name);

                for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
                        if ((pdev->resets_supported & BIT(i)) &&
                            sysfs_streq(name, pci_reset_fn_methods[i].name)) {
                                resets_enabled |= BIT(i);
                                break;
                        }
                }
...
        }

set_reset_methods:
        kfree(options);
        pdev->resets_enabled =  resets_enabled;
        return count;
}

static ssize_t reset_method_show(struct device *dev,
                                 struct device_attribute *attr,
                                 char *buf)
{
        struct pci_dev *pdev = to_pci_dev(dev);
        ssize_t len = 0;
        int i;

        for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
                if (pdev->resets_enabled & BIT(i))
                        len += sysfs_emit_at(buf, len, "%s%s",
                                             len ? "," : "",
                                             pci_reset_fn_methods[i].name);
        }
        len += sysfs_emit_at(buf, len, len ? "\n" : "");

        return len;
}

2021-06-21 17:17:25

by Amey Narkhede

[permalink] [raw]
Subject: Re: [PATCH v7 2/8] PCI: Add new array for keeping track of ordering of reset methods

On 21/06/21 10:02AM, Shanker R Donthineni wrote:
> Hi Bjorn,
>
> On 6/18/21 12:22 PM, Amey Narkhede wrote:
> > I wonder if this would be easier if dev->reset_methods[] contained
> > indices into pci_reset_fn_methods[], highest priority first, with the
> > priority being determined when dev->reset_methods[] is updated. For
> > example:
> >
> > const struct pci_reset_fn_method pci_reset_fn_methods[] = {
> > { }, # 0
> > { &pci_dev_specific_reset, .name = "device_specific" }, # 1
> > { &pci_dev_acpi_reset, .name = "acpi" }, # 2
> > { &pcie_reset_flr, .name = "flr" }, # 3
> > { &pci_af_flr, .name = "af_flr" }, # 4
> > { &pci_pm_reset, .name = "pm" }, # 5
> > { &pci_reset_bus_function, .name = "bus" }, # 6
> > };
> >
> > dev->reset_methods[] = [1, 2, 3, 4, 5, 6]
> > means all reset methods are supported, in the default priority
> > order
> >
> > dev->reset_methods[] = [1, 0, 0, 0, 0, 0]
> > means only pci_dev_specific_reset is supported
> >
> > dev->reset_methods[] = [3, 5, 0, 0, 0, 0]
> > means pcie_reset_flr and pci_pm_reset are supported, in that
> > priority order
> What about keeping two bitmap fields 'resets_supported' and 'resets_enabled' in
> pci_dev object and mange it through sysfs and probe helper function. We can avoid
> two loops multiple paces and takes only 2Bytes of memory to keep track resets.
>
> resets_supported? ---> initialized during pci_dev setup
> resets_enabled ---> Exposed to userspace through sysfs by default set to resets_supported
>
> include/linux/pci.h:
> ------------------------
> /* Different types of PCI resets possible, lower number is higher priority */
> #define PCI_RESET_METHOD_DEVSPEC ??? 0
> #define PCI_RESET_METHOD_ACPI??????????? 1
> #define PCI_RESET_METHOD_FLR????????????? 2
> #define PCI_RESET_METHOD_Af_FLR???????? 3
> #define PCI_RESET_METHOD_PM?????????????? 4
> #define PCI_RESET_METHOD_BUS???????????? 5
> #define PCI_RESET_METHOD_MAX??????????? 6
>
> struct pci_dev {
> ??? ...
> ??????? u8????????????? resets_supported;
> ??????? u8????????????? resets_enabled;
> };
>
> static inline bool pci_reset_supported(struct pci_dev *dev)
> {
> ??????? return !!(dev->resets_supported);
> }
>
>
> drivers/pci/pci.c:
> --------------------
> const struct pci_reset_fn_method pci_reset_fn_methods[PCI_RESET_METHOD_MAX] = {
> ??????? [PCI_RESET_METHOD_DEVSPEC] = { &pci_dev_specific_reset,
> ?????????????????????????????????????????????????????????????????? .name = "device_specific" },
> ??????? [PCI_RESET_METHOD_ACPI] = { &pci_dev_acpi_reset, .name = "acpi" },
> ??????? [PCI_RESET_METHOD_FLR] = { &pcie_reset_flr, .name = "flr" },
> ??????? [PCI_RESET_METHOD_Af_FLR] = { &pci_af_flr, .name = "af_flr" },
> ??????? [PCI_RESET_METHOD_PM] = { &pci_pm_reset, .name = "pm" },
> ??????? [PCI_RESET_METHOD_BUS] = { &pci_reset_bus_function, .name = "bus" }
> };
>
>
> void pci_init_reset_methods(struct pci_dev *dev)
> {
> ??????? int i, rc;
>
> ??????? BUILD_BUG_ON(ARRAY_SIZE(pci_reset_fn_methods) != PCI_RESET_METHOD_MAX);
> ??????? might_sleep();
>
> ??????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> ??????????????? rc = pci_reset_fn_methods[i].reset_fn(dev, PCI_RESET_PROBE);
> ??????????????? if (!rc)
> ??????????????????????? dev->resets_supported |= BIT(i);
> ??????????????? else if (rc != -ENOTTY)
> ??????????????????????? break;
> ??????? }
> ??????? dev->resets_enabled = dev->resets_supported;
> }
>
> int __pci_reset_function_locked(struct pci_dev *dev)
> {
> ??????? int i, rc = -ENOTTY;
>
> ??????? might_sleep();
>
> ??????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> ??????????????? if (dev->resets_enabled & BIT(i)) {
> ??????????????????????? rc = pci_reset_fn_methods[i].reset_fn(dev, 0);
> ??????????????????????? if (rc != -ENOTTY)
> ??????????????????????????????? return rc;
> ??????????????? }
> ??????? }
>
> ??????? if (rc == -ENOTTY)
> ??????????????? pci_warn(dev, "No reset happened reason %s\n",
> ???????????????????????? !!dev->resets_supported ?
> ???????????????????????? "disabled by user" : "not supported");
>
> ??????? return rc;
> }
>
> drivers/pci/pci-sysfs.c
> ----------------------------
> 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);
> ??????? u8 resets_enabled = 0;
> ...
> ??????? if (sysfs_streq(options, "default")) {
> ??????????????? pdev->resets_enabled = pdev->resets_supported;
> ??????????????? goto set_reset_methods;
> ??????? }
>
> ??????? while ((name = strsep(&options, ",")) != NULL) {
> ??????????????? if (sysfs_streq(name, ""))
> ??????????????????????? continue;
> ??????????????? name = strim(name);
>
> ??????????????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> ??????????????????????? if ((pdev->resets_supported & BIT(i)) &&
> ??????????????????????????? sysfs_streq(name, pci_reset_fn_methods[i].name)) {
> ??????????????????????????????? resets_enabled |= BIT(i);
> ??????????????????????????????? break;
> ??????????????????????? }
> ??????????????? }
> ...
> ??????? }
>
> set_reset_methods:
> ??????? kfree(options);
> ??????? pdev->resets_enabled =? resets_enabled;
> ??????? return count;
> }
>
> static ssize_t reset_method_show(struct device *dev,
> ???????????????????????????????? struct device_attribute *attr,
> ???????????????????????????????? char *buf)
> {
> ??????? struct pci_dev *pdev = to_pci_dev(dev);
> ??????? ssize_t len = 0;
> ??????? int i;
>
> ??????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> ??????????????? if (pdev->resets_enabled & BIT(i))
> ??????????????????????? len += sysfs_emit_at(buf, len, "%s%s",
> ???????????????????????????????????????????? len ? "," : "",
> ???????????????????????????????????????????? pci_reset_fn_methods[i].name);
> ??????? }
> ??????? len += sysfs_emit_at(buf, len, len ? "\n" : "");
>
> ??????? return len;
> }
>
Thank you for the idea.
Actually that would be coming full circle because Alex, Raphael and I
tried similar approach earlier while prototyping for v2 but this implementation
does look better than what I had at that time.

Thanks,
Amey

2021-06-21 18:40:53

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v7 2/8] PCI: Add new array for keeping track of ordering of reset methods

On Mon, Jun 21, 2021 at 10:45:18PM +0530, Amey Narkhede wrote:
> On 21/06/21 10:02AM, Shanker R Donthineni wrote:
> > On 6/18/21 12:22 PM, Amey Narkhede wrote:
> > > I wonder if this would be easier if dev->reset_methods[] contained
> > > indices into pci_reset_fn_methods[], highest priority first, with the
> > > priority being determined when dev->reset_methods[] is updated. For
> > > example:
> > >
> > > const struct pci_reset_fn_method pci_reset_fn_methods[] = {
> > > { }, # 0
> > > { &pci_dev_specific_reset, .name = "device_specific" }, # 1
> > > { &pci_dev_acpi_reset, .name = "acpi" }, # 2
> > > { &pcie_reset_flr, .name = "flr" }, # 3
> > > { &pci_af_flr, .name = "af_flr" }, # 4
> > > { &pci_pm_reset, .name = "pm" }, # 5
> > > { &pci_reset_bus_function, .name = "bus" }, # 6
> > > };
> > >
> > > dev->reset_methods[] = [1, 2, 3, 4, 5, 6]
> > > means all reset methods are supported, in the default priority
> > > order
> > >
> > > dev->reset_methods[] = [1, 0, 0, 0, 0, 0]
> > > means only pci_dev_specific_reset is supported
> > >
> > > dev->reset_methods[] = [3, 5, 0, 0, 0, 0]
> > > means pcie_reset_flr and pci_pm_reset are supported, in that
> > > priority order
> >
> > What about keeping two bitmap fields 'resets_supported' and
> > 'resets_enabled' in pci_dev object and mange it through sysfs and
> > probe helper function. We can avoid two loops multiple paces and
> > takes only 2Bytes of memory to keep track resets.
> >
> > resets_supported? ---> initialized during pci_dev setup
> > resets_enabled ---> Exposed to userspace through sysfs by default set to resets_supported
> >
> > include/linux/pci.h:
> > ------------------------
> > /* Different types of PCI resets possible, lower number is higher priority */
> > #define PCI_RESET_METHOD_DEVSPEC ??? 0
> > #define PCI_RESET_METHOD_ACPI??????????? 1
> > #define PCI_RESET_METHOD_FLR????????????? 2
> > #define PCI_RESET_METHOD_Af_FLR???????? 3
> > #define PCI_RESET_METHOD_PM?????????????? 4
> > #define PCI_RESET_METHOD_BUS???????????? 5
> > #define PCI_RESET_METHOD_MAX??????????? 6
> >
> > struct pci_dev {
> > ??? ...
> > ??????? u8????????????? resets_supported;
> > ??????? u8????????????? resets_enabled;
> > };
> >
> > static inline bool pci_reset_supported(struct pci_dev *dev)
> > {
> > ??????? return !!(dev->resets_supported);
> > }
> >
> >
> > drivers/pci/pci.c:
> > --------------------
> > const struct pci_reset_fn_method pci_reset_fn_methods[PCI_RESET_METHOD_MAX] = {
> > ??????? [PCI_RESET_METHOD_DEVSPEC] = { &pci_dev_specific_reset,
> > ?????????????????????????????????????????????????????????????????? .name = "device_specific" },
> > ??????? [PCI_RESET_METHOD_ACPI] = { &pci_dev_acpi_reset, .name = "acpi" },
> > ??????? [PCI_RESET_METHOD_FLR] = { &pcie_reset_flr, .name = "flr" },
> > ??????? [PCI_RESET_METHOD_Af_FLR] = { &pci_af_flr, .name = "af_flr" },
> > ??????? [PCI_RESET_METHOD_PM] = { &pci_pm_reset, .name = "pm" },
> > ??????? [PCI_RESET_METHOD_BUS] = { &pci_reset_bus_function, .name = "bus" }
> > };
> >
> >
> > void pci_init_reset_methods(struct pci_dev *dev)
> > {
> > ??????? int i, rc;
> >
> > ??????? BUILD_BUG_ON(ARRAY_SIZE(pci_reset_fn_methods) != PCI_RESET_METHOD_MAX);
> > ??????? might_sleep();
> >
> > ??????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> > ??????????????? rc = pci_reset_fn_methods[i].reset_fn(dev, PCI_RESET_PROBE);
> > ??????????????? if (!rc)
> > ??????????????????????? dev->resets_supported |= BIT(i);
> > ??????????????? else if (rc != -ENOTTY)
> > ??????????????????????? break;
> > ??????? }
> > ??????? dev->resets_enabled = dev->resets_supported;
> > }
> >
> > int __pci_reset_function_locked(struct pci_dev *dev)
> > {
> > ??????? int i, rc = -ENOTTY;
> >
> > ??????? might_sleep();
> >
> > ??????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> > ??????????????? if (dev->resets_enabled & BIT(i)) {
> > ??????????????????????? rc = pci_reset_fn_methods[i].reset_fn(dev, 0);
> > ??????????????????????? if (rc != -ENOTTY)
> > ??????????????????????????????? return rc;
> > ??????????????? }
> > ??????? }
> >
> > ??????? if (rc == -ENOTTY)
> > ??????????????? pci_warn(dev, "No reset happened reason %s\n",
> > ???????????????????????? !!dev->resets_supported ?
> > ???????????????????????? "disabled by user" : "not supported");
> >
> > ??????? return rc;
> > }
> >
> > drivers/pci/pci-sysfs.c
> > ----------------------------
> > 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);
> > ??????? u8 resets_enabled = 0;
> > ...
> > ??????? if (sysfs_streq(options, "default")) {
> > ??????????????? pdev->resets_enabled = pdev->resets_supported;
> > ??????????????? goto set_reset_methods;
> > ??????? }
> >
> > ??????? while ((name = strsep(&options, ",")) != NULL) {
> > ??????????????? if (sysfs_streq(name, ""))
> > ??????????????????????? continue;
> > ??????????????? name = strim(name);
> >
> > ??????????????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> > ??????????????????????? if ((pdev->resets_supported & BIT(i)) &&
> > ??????????????????????????? sysfs_streq(name, pci_reset_fn_methods[i].name)) {
> > ??????????????????????????????? resets_enabled |= BIT(i);
> > ??????????????????????????????? break;
> > ??????????????????????? }
> > ??????????????? }
> > ...
> > ??????? }
> >
> > set_reset_methods:
> > ??????? kfree(options);
> > ??????? pdev->resets_enabled =? resets_enabled;
> > ??????? return count;
> > }
> >
> > static ssize_t reset_method_show(struct device *dev,
> > ???????????????????????????????? struct device_attribute *attr,
> > ???????????????????????????????? char *buf)
> > {
> > ??????? struct pci_dev *pdev = to_pci_dev(dev);
> > ??????? ssize_t len = 0;
> > ??????? int i;
> >
> > ??????? for (i = 0; i < PCI_RESET_METHOD_MAX; i++) {
> > ??????????????? if (pdev->resets_enabled & BIT(i))
> > ??????????????????????? len += sysfs_emit_at(buf, len, "%s%s",
> > ???????????????????????????????????????????? len ? "," : "",
> > ???????????????????????????????????????????? pci_reset_fn_methods[i].name);
> > ??????? }
> > ??????? len += sysfs_emit_at(buf, len, len ? "\n" : "");
> >
> > ??????? return len;
> > }
> >
> Thank you for the idea.
> Actually that would be coming full circle because Alex, Raphael and
> I tried similar approach earlier while prototyping for v2 but this
> implementation does look better than what I had at that time.

I thought part of the point of this series was to allow the user to
change the *order* of reset types. I don't think we can control the
ordering if we only keep a bit (or even two) per reset type.