Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'pci/reset'

- Cache PCIe Device Capabilities register (Amey Narkhede)

- Add pcie_reset_flr() with 'probe' argument (Amey Narkhede)

- Add pdev->reset_methods[] array to track reset method ordering (Amey
Narkhede)

- Remove reset_fn field from pci_dev (Amey Narkhede)

- Add sysfs interface to query and set device reset mechanism (Amey
Narkhede)

- Add pci_set_acpi_fwnode() to set ACPI_COMPANION (Shanker Donthineni)

- Use acpi_pci_power_manageable() instead of duplicating logic (Shanker
Donthineni)

- Set ACPI fwnode early and at the same time with OF (Shanker Donthineni)

- Add support for ACPI _RST reset method (Shanker Donthineni)

- Change reset function 'probe' argument to bool (Amey Narkhede)

* pci/reset:
PCI: Change the type of probe argument in reset functions
PCI: Add support for ACPI _RST reset method
PCI: Setup ACPI fwnode early and at the same time with OF
PCI: Use acpi_pci_power_manageable()
PCI: Add pci_set_acpi_fwnode() to set ACPI_COMPANION
PCI: Allow userspace to query and set device reset mechanism
PCI: Remove reset_fn field from pci_dev
PCI: Add array to track reset method ordering
PCI: Add pcie_reset_flr() with 'probe' argument
PCI: Cache PCIe Device Capabilities register

+359 -166
+17
Documentation/ABI/testing/sysfs-bus-pci
··· 121 121 child buses, and re-discover devices removed earlier 122 122 from this part of the device tree. 123 123 124 + What: /sys/bus/pci/devices/.../reset_method 125 + Date: August 2021 126 + Contact: Amey Narkhede <ameynarkhede03@gmail.com> 127 + Description: 128 + Some devices allow an individual function to be reset 129 + without affecting other functions in the same slot. 130 + 131 + For devices that have this support, a file named 132 + reset_method is present in sysfs. Reading this file 133 + gives names of the supported and enabled reset methods and 134 + their ordering. Writing a space-separated list of names of 135 + reset methods sets the reset methods and ordering to be 136 + used when resetting the device. Writing an empty string 137 + disables the ability to reset the device. Writing 138 + "default" enables all supported reset methods in the 139 + default ordering. 140 + 124 141 What: /sys/bus/pci/devices/.../reset 125 142 Date: July 2009 126 143 Contact: Michael S. Tsirkin <mst@redhat.com>
+1 -3
drivers/crypto/cavium/nitrox/nitrox_main.c
··· 306 306 return -ENOMEM; 307 307 } 308 308 309 - /* check flr support */ 310 - if (pcie_has_flr(pdev)) 311 - pcie_flr(pdev); 309 + pcie_reset_flr(pdev, PCI_RESET_DO_RESET); 312 310 313 311 pci_restore_state(pdev); 314 312
+1 -1
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
··· 526 526 oct->irq_name_storage = NULL; 527 527 } 528 528 /* Soft reset the octeon device before exiting */ 529 - if (oct->pci_dev->reset_fn) 529 + if (!pcie_reset_flr(oct->pci_dev, PCI_RESET_PROBE)) 530 530 octeon_pci_flr(oct); 531 531 else 532 532 cn23xx_vf_ask_pf_to_do_flr(oct);
+1 -1
drivers/pci/hotplug/pciehp.h
··· 184 184 185 185 int pciehp_sysfs_enable_slot(struct hotplug_slot *hotplug_slot); 186 186 int pciehp_sysfs_disable_slot(struct hotplug_slot *hotplug_slot); 187 - int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, int probe); 187 + int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, bool probe); 188 188 int pciehp_get_attention_status(struct hotplug_slot *hotplug_slot, u8 *status); 189 189 int pciehp_set_raw_indicator_status(struct hotplug_slot *h_slot, u8 status); 190 190 int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status);
+1 -1
drivers/pci/hotplug/pciehp_hpc.c
··· 870 870 * momentarily, if we see that they could interfere. Also, clear any spurious 871 871 * events after. 872 872 */ 873 - int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, int probe) 873 + int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, bool probe) 874 874 { 875 875 struct controller *ctrl = to_ctrl(hotplug_slot); 876 876 struct pci_dev *pdev = ctrl_dev(ctrl);
+1 -1
drivers/pci/hotplug/pnv_php.c
··· 526 526 return 0; 527 527 } 528 528 529 - static int pnv_php_reset_slot(struct hotplug_slot *slot, int probe) 529 + static int pnv_php_reset_slot(struct hotplug_slot *slot, bool probe) 530 530 { 531 531 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot); 532 532 struct pci_dev *bridge = php_slot->pdev;
+61 -42
drivers/pci/pci-acpi.c
··· 934 934 935 935 static struct acpi_device *acpi_pci_find_companion(struct device *dev); 936 936 937 - static bool acpi_pci_bridge_d3(struct pci_dev *dev) 937 + void pci_set_acpi_fwnode(struct pci_dev *dev) 938 938 { 939 - const struct fwnode_handle *fwnode; 940 - struct acpi_device *adev; 941 - struct pci_dev *root; 942 - u8 val; 939 + if (!ACPI_COMPANION(&dev->dev) && !pci_dev_is_added(dev)) 940 + ACPI_COMPANION_SET(&dev->dev, 941 + acpi_pci_find_companion(&dev->dev)); 942 + } 943 943 944 - if (!dev->is_hotplug_bridge) 945 - return false; 944 + /** 945 + * pci_dev_acpi_reset - do a function level reset using _RST method 946 + * @dev: device to reset 947 + * @probe: if true, return 0 if device supports _RST 948 + */ 949 + int pci_dev_acpi_reset(struct pci_dev *dev, bool probe) 950 + { 951 + acpi_handle handle = ACPI_HANDLE(&dev->dev); 946 952 947 - /* Assume D3 support if the bridge is power-manageable by ACPI. */ 948 - adev = ACPI_COMPANION(&dev->dev); 949 - if (!adev && !pci_dev_is_added(dev)) { 950 - adev = acpi_pci_find_companion(&dev->dev); 951 - ACPI_COMPANION_SET(&dev->dev, adev); 953 + if (!handle || !acpi_has_method(handle, "_RST")) 954 + return -ENOTTY; 955 + 956 + if (probe) 957 + return 0; 958 + 959 + if (ACPI_FAILURE(acpi_evaluate_object(handle, "_RST", NULL, NULL))) { 960 + pci_warn(dev, "ACPI _RST failed\n"); 961 + return -ENOTTY; 952 962 } 953 963 954 - if (adev && acpi_device_power_manageable(adev)) 955 - return true; 956 - 957 - /* 958 - * Look for a special _DSD property for the root port and if it 959 - * is set we know the hierarchy behind it supports D3 just fine. 960 - */ 961 - root = pcie_find_root_port(dev); 962 - if (!root) 963 - return false; 964 - 965 - adev = ACPI_COMPANION(&root->dev); 966 - if (root == dev) { 967 - /* 968 - * It is possible that the ACPI companion is not yet bound 969 - * for the root port so look it up manually here. 970 - */ 971 - if (!adev && !pci_dev_is_added(root)) 972 - adev = acpi_pci_find_companion(&root->dev); 973 - } 974 - 975 - if (!adev) 976 - return false; 977 - 978 - fwnode = acpi_fwnode_handle(adev); 979 - if (fwnode_property_read_u8(fwnode, "HotPlugSupportInD3", &val)) 980 - return false; 981 - 982 - return val == 1; 964 + return 0; 983 965 } 984 966 985 967 static bool acpi_pci_power_manageable(struct pci_dev *dev) 986 968 { 987 969 struct acpi_device *adev = ACPI_COMPANION(&dev->dev); 988 - return adev ? acpi_device_power_manageable(adev) : false; 970 + 971 + if (!adev) 972 + return false; 973 + return acpi_device_power_manageable(adev); 974 + } 975 + 976 + static bool acpi_pci_bridge_d3(struct pci_dev *dev) 977 + { 978 + const union acpi_object *obj; 979 + struct acpi_device *adev; 980 + struct pci_dev *rpdev; 981 + 982 + if (!dev->is_hotplug_bridge) 983 + return false; 984 + 985 + /* Assume D3 support if the bridge is power-manageable by ACPI. */ 986 + if (acpi_pci_power_manageable(dev)) 987 + return true; 988 + 989 + /* 990 + * The ACPI firmware will provide the device-specific properties through 991 + * _DSD configuration object. Look for the 'HotPlugSupportInD3' property 992 + * for the root port and if it is set we know the hierarchy behind it 993 + * supports D3 just fine. 994 + */ 995 + rpdev = pcie_find_root_port(dev); 996 + if (!rpdev) 997 + return false; 998 + 999 + adev = ACPI_COMPANION(&rpdev->dev); 1000 + if (!adev) 1001 + return false; 1002 + 1003 + if (acpi_dev_get_property(adev, "HotPlugSupportInD3", 1004 + ACPI_TYPE_INTEGER, &obj) < 0) 1005 + return false; 1006 + 1007 + return obj->integer.value == 1; 989 1008 } 990 1009 991 1010 static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
+2 -1
drivers/pci/pci-sysfs.c
··· 1367 1367 { 1368 1368 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); 1369 1369 1370 - if (!pdev->reset_fn) 1370 + if (!pci_reset_supported(pdev)) 1371 1371 return 0; 1372 1372 1373 1373 return a->mode; ··· 1491 1491 &pci_dev_config_attr_group, 1492 1492 &pci_dev_rom_attr_group, 1493 1493 &pci_dev_reset_attr_group, 1494 + &pci_dev_reset_method_attr_group, 1494 1495 &pci_dev_vpd_attr_group, 1495 1496 #ifdef CONFIG_DMI 1496 1497 &pci_dev_smbios_attr_group,
+218 -79
drivers/pci/pci.c
··· 31 31 #include <linux/vmalloc.h> 32 32 #include <asm/dma.h> 33 33 #include <linux/aer.h> 34 + #include <linux/bitfield.h> 34 35 #include "pci.h" 35 36 36 37 DEFINE_MUTEX(pci_slot_mutex); ··· 71 70 72 71 if (delay) 73 72 msleep(delay); 73 + } 74 + 75 + bool pci_reset_supported(struct pci_dev *dev) 76 + { 77 + return dev->reset_methods[0] != 0; 74 78 } 75 79 76 80 #ifdef CONFIG_PCI_DOMAINS ··· 4628 4622 EXPORT_SYMBOL(pci_wait_for_pending_transaction); 4629 4623 4630 4624 /** 4631 - * pcie_has_flr - check if a device supports function level resets 4632 - * @dev: device to check 4633 - * 4634 - * Returns true if the device advertises support for PCIe function level 4635 - * resets. 4636 - */ 4637 - bool pcie_has_flr(struct pci_dev *dev) 4638 - { 4639 - u32 cap; 4640 - 4641 - if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) 4642 - return false; 4643 - 4644 - pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap); 4645 - return cap & PCI_EXP_DEVCAP_FLR; 4646 - } 4647 - EXPORT_SYMBOL_GPL(pcie_has_flr); 4648 - 4649 - /** 4650 4625 * pcie_flr - initiate a PCIe function level reset 4651 4626 * @dev: device to reset 4652 4627 * 4653 - * Initiate a function level reset on @dev. The caller should ensure the 4654 - * device supports FLR before calling this function, e.g. by using the 4655 - * pcie_has_flr() helper. 4628 + * Initiate a function level reset unconditionally on @dev without 4629 + * checking any flags and DEVCAP 4656 4630 */ 4657 4631 int pcie_flr(struct pci_dev *dev) 4658 4632 { ··· 4655 4669 } 4656 4670 EXPORT_SYMBOL_GPL(pcie_flr); 4657 4671 4658 - static int pci_af_flr(struct pci_dev *dev, int probe) 4672 + /** 4673 + * pcie_reset_flr - initiate a PCIe function level reset 4674 + * @dev: device to reset 4675 + * @probe: if true, return 0 if device can be reset this way 4676 + * 4677 + * Initiate a function level reset on @dev. 4678 + */ 4679 + int pcie_reset_flr(struct pci_dev *dev, bool probe) 4680 + { 4681 + if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) 4682 + return -ENOTTY; 4683 + 4684 + if (!(dev->devcap & PCI_EXP_DEVCAP_FLR)) 4685 + return -ENOTTY; 4686 + 4687 + if (probe) 4688 + return 0; 4689 + 4690 + return pcie_flr(dev); 4691 + } 4692 + EXPORT_SYMBOL_GPL(pcie_reset_flr); 4693 + 4694 + static int pci_af_flr(struct pci_dev *dev, bool probe) 4659 4695 { 4660 4696 int pos; 4661 4697 u8 cap; ··· 4724 4716 /** 4725 4717 * pci_pm_reset - Put device into PCI_D3 and back into PCI_D0. 4726 4718 * @dev: Device to reset. 4727 - * @probe: If set, only check if the device can be reset this way. 4719 + * @probe: if true, return 0 if the device can be reset this way. 4728 4720 * 4729 4721 * If @dev supports native PCI PM and its PCI_PM_CTRL_NO_SOFT_RESET flag is 4730 4722 * unset, it will be reinitialized internally when going from PCI_D3hot to ··· 4736 4728 * by default (i.e. unless the @dev's d3hot_delay field has a different value). 4737 4729 * Moreover, only devices in D0 can be reset by this function. 4738 4730 */ 4739 - static int pci_pm_reset(struct pci_dev *dev, int probe) 4731 + static int pci_pm_reset(struct pci_dev *dev, bool probe) 4740 4732 { 4741 4733 u16 csr; 4742 4734 ··· 4996 4988 } 4997 4989 EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset); 4998 4990 4999 - static int pci_parent_bus_reset(struct pci_dev *dev, int probe) 4991 + static int pci_parent_bus_reset(struct pci_dev *dev, bool probe) 5000 4992 { 5001 4993 struct pci_dev *pdev; 5002 4994 ··· 5014 5006 return pci_bridge_secondary_bus_reset(dev->bus->self); 5015 5007 } 5016 5008 5017 - static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, int probe) 5009 + static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, bool probe) 5018 5010 { 5019 5011 int rc = -ENOTTY; 5020 5012 ··· 5029 5021 return rc; 5030 5022 } 5031 5023 5032 - static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) 5024 + static int pci_dev_reset_slot_function(struct pci_dev *dev, bool probe) 5033 5025 { 5034 5026 if (dev->multifunction || dev->subordinate || !dev->slot || 5035 5027 dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET) ··· 5038 5030 return pci_reset_hotplug_slot(dev->slot->hotplug, probe); 5039 5031 } 5040 5032 5041 - static int pci_reset_bus_function(struct pci_dev *dev, int probe) 5033 + static int pci_reset_bus_function(struct pci_dev *dev, bool probe) 5042 5034 { 5043 5035 int rc; 5044 5036 ··· 5122 5114 err_handler->reset_done(dev); 5123 5115 } 5124 5116 5117 + /* dev->reset_methods[] is a 0-terminated list of indices into this array */ 5118 + static const struct pci_reset_fn_method pci_reset_fn_methods[] = { 5119 + { }, 5120 + { pci_dev_specific_reset, .name = "device_specific" }, 5121 + { pci_dev_acpi_reset, .name = "acpi" }, 5122 + { pcie_reset_flr, .name = "flr" }, 5123 + { pci_af_flr, .name = "af_flr" }, 5124 + { pci_pm_reset, .name = "pm" }, 5125 + { pci_reset_bus_function, .name = "bus" }, 5126 + }; 5127 + 5128 + static ssize_t reset_method_show(struct device *dev, 5129 + struct device_attribute *attr, char *buf) 5130 + { 5131 + struct pci_dev *pdev = to_pci_dev(dev); 5132 + ssize_t len = 0; 5133 + int i, m; 5134 + 5135 + for (i = 0; i < PCI_NUM_RESET_METHODS; i++) { 5136 + m = pdev->reset_methods[i]; 5137 + if (!m) 5138 + break; 5139 + 5140 + len += sysfs_emit_at(buf, len, "%s%s", len ? " " : "", 5141 + pci_reset_fn_methods[m].name); 5142 + } 5143 + 5144 + if (len) 5145 + len += sysfs_emit_at(buf, len, "\n"); 5146 + 5147 + return len; 5148 + } 5149 + 5150 + static int reset_method_lookup(const char *name) 5151 + { 5152 + int m; 5153 + 5154 + for (m = 1; m < PCI_NUM_RESET_METHODS; m++) { 5155 + if (sysfs_streq(name, pci_reset_fn_methods[m].name)) 5156 + return m; 5157 + } 5158 + 5159 + return 0; /* not found */ 5160 + } 5161 + 5162 + static ssize_t reset_method_store(struct device *dev, 5163 + struct device_attribute *attr, 5164 + const char *buf, size_t count) 5165 + { 5166 + struct pci_dev *pdev = to_pci_dev(dev); 5167 + char *options, *name; 5168 + int m, n; 5169 + u8 reset_methods[PCI_NUM_RESET_METHODS] = { 0 }; 5170 + 5171 + if (sysfs_streq(buf, "")) { 5172 + pdev->reset_methods[0] = 0; 5173 + pci_warn(pdev, "All device reset methods disabled by user"); 5174 + return count; 5175 + } 5176 + 5177 + if (sysfs_streq(buf, "default")) { 5178 + pci_init_reset_methods(pdev); 5179 + return count; 5180 + } 5181 + 5182 + options = kstrndup(buf, count, GFP_KERNEL); 5183 + if (!options) 5184 + return -ENOMEM; 5185 + 5186 + n = 0; 5187 + while ((name = strsep(&options, " ")) != NULL) { 5188 + if (sysfs_streq(name, "")) 5189 + continue; 5190 + 5191 + name = strim(name); 5192 + 5193 + m = reset_method_lookup(name); 5194 + if (!m) { 5195 + pci_err(pdev, "Invalid reset method '%s'", name); 5196 + goto error; 5197 + } 5198 + 5199 + if (pci_reset_fn_methods[m].reset_fn(pdev, PCI_RESET_PROBE)) { 5200 + pci_err(pdev, "Unsupported reset method '%s'", name); 5201 + goto error; 5202 + } 5203 + 5204 + if (n == PCI_NUM_RESET_METHODS - 1) { 5205 + pci_err(pdev, "Too many reset methods\n"); 5206 + goto error; 5207 + } 5208 + 5209 + reset_methods[n++] = m; 5210 + } 5211 + 5212 + reset_methods[n] = 0; 5213 + 5214 + /* Warn if dev-specific supported but not highest priority */ 5215 + if (pci_reset_fn_methods[1].reset_fn(pdev, PCI_RESET_PROBE) == 0 && 5216 + reset_methods[0] != 1) 5217 + pci_warn(pdev, "Device-specific reset disabled/de-prioritized by user"); 5218 + memcpy(pdev->reset_methods, reset_methods, sizeof(pdev->reset_methods)); 5219 + kfree(options); 5220 + return count; 5221 + 5222 + error: 5223 + /* Leave previous methods unchanged */ 5224 + kfree(options); 5225 + return -EINVAL; 5226 + } 5227 + static DEVICE_ATTR_RW(reset_method); 5228 + 5229 + static struct attribute *pci_dev_reset_method_attrs[] = { 5230 + &dev_attr_reset_method.attr, 5231 + NULL, 5232 + }; 5233 + 5234 + static umode_t pci_dev_reset_method_attr_is_visible(struct kobject *kobj, 5235 + struct attribute *a, int n) 5236 + { 5237 + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); 5238 + 5239 + if (!pci_reset_supported(pdev)) 5240 + return 0; 5241 + 5242 + return a->mode; 5243 + } 5244 + 5245 + const struct attribute_group pci_dev_reset_method_attr_group = { 5246 + .attrs = pci_dev_reset_method_attrs, 5247 + .is_visible = pci_dev_reset_method_attr_is_visible, 5248 + }; 5249 + 5125 5250 /** 5126 5251 * __pci_reset_function_locked - reset a PCI device function while holding 5127 5252 * the @dev mutex lock. ··· 5277 5136 */ 5278 5137 int __pci_reset_function_locked(struct pci_dev *dev) 5279 5138 { 5280 - int rc; 5139 + int i, m, rc = -ENOTTY; 5281 5140 5282 5141 might_sleep(); 5283 5142 5284 5143 /* 5285 - * A reset method returns -ENOTTY if it doesn't support this device 5286 - * and we should try the next method. 5144 + * A reset method returns -ENOTTY if it doesn't support this device and 5145 + * we should try the next method. 5287 5146 * 5288 - * If it returns 0 (success), we're finished. If it returns any 5289 - * other error, we're also finished: this indicates that further 5290 - * reset mechanisms might be broken on the device. 5147 + * If it returns 0 (success), we're finished. If it returns any other 5148 + * error, we're also finished: this indicates that further reset 5149 + * mechanisms might be broken on the device. 5291 5150 */ 5292 - rc = pci_dev_specific_reset(dev, 0); 5293 - if (rc != -ENOTTY) 5294 - return rc; 5295 - if (pcie_has_flr(dev)) { 5296 - rc = pcie_flr(dev); 5151 + for (i = 0; i < PCI_NUM_RESET_METHODS; i++) { 5152 + m = dev->reset_methods[i]; 5153 + if (!m) 5154 + return -ENOTTY; 5155 + 5156 + rc = pci_reset_fn_methods[m].reset_fn(dev, PCI_RESET_DO_RESET); 5157 + if (!rc) 5158 + return 0; 5297 5159 if (rc != -ENOTTY) 5298 5160 return rc; 5299 5161 } 5300 - rc = pci_af_flr(dev, 0); 5301 - if (rc != -ENOTTY) 5302 - return rc; 5303 - rc = pci_pm_reset(dev, 0); 5304 - if (rc != -ENOTTY) 5305 - return rc; 5306 - return pci_reset_bus_function(dev, 0); 5162 + 5163 + return -ENOTTY; 5307 5164 } 5308 5165 EXPORT_SYMBOL_GPL(__pci_reset_function_locked); 5309 5166 5310 5167 /** 5311 - * pci_probe_reset_function - check whether the device can be safely reset 5312 - * @dev: PCI device to reset 5168 + * pci_init_reset_methods - check whether device can be safely reset 5169 + * and store supported reset mechanisms. 5170 + * @dev: PCI device to check for reset mechanisms 5313 5171 * 5314 5172 * Some devices allow an individual function to be reset without affecting 5315 - * other functions in the same device. The PCI device must be responsive 5316 - * to PCI config space in order to use this function. 5173 + * other functions in the same device. The PCI device must be in D0-D3hot 5174 + * state. 5317 5175 * 5318 - * Returns 0 if the device function can be reset or negative if the 5319 - * device doesn't support resetting a single function. 5176 + * Stores reset mechanisms supported by device in reset_methods byte array 5177 + * which is a member of struct pci_dev. 5320 5178 */ 5321 - int pci_probe_reset_function(struct pci_dev *dev) 5179 + void pci_init_reset_methods(struct pci_dev *dev) 5322 5180 { 5323 - int rc; 5181 + int m, i, rc; 5182 + 5183 + BUILD_BUG_ON(ARRAY_SIZE(pci_reset_fn_methods) != PCI_NUM_RESET_METHODS); 5324 5184 5325 5185 might_sleep(); 5326 5186 5327 - rc = pci_dev_specific_reset(dev, 1); 5328 - if (rc != -ENOTTY) 5329 - return rc; 5330 - if (pcie_has_flr(dev)) 5331 - return 0; 5332 - rc = pci_af_flr(dev, 1); 5333 - if (rc != -ENOTTY) 5334 - return rc; 5335 - rc = pci_pm_reset(dev, 1); 5336 - if (rc != -ENOTTY) 5337 - return rc; 5187 + i = 0; 5188 + for (m = 1; m < PCI_NUM_RESET_METHODS; m++) { 5189 + rc = pci_reset_fn_methods[m].reset_fn(dev, PCI_RESET_PROBE); 5190 + if (!rc) 5191 + dev->reset_methods[i++] = m; 5192 + else if (rc != -ENOTTY) 5193 + break; 5194 + } 5338 5195 5339 - return pci_reset_bus_function(dev, 1); 5196 + dev->reset_methods[i] = 0; 5340 5197 } 5341 5198 5342 5199 /** ··· 5357 5218 { 5358 5219 int rc; 5359 5220 5360 - if (!dev->reset_fn) 5221 + if (!pci_reset_supported(dev)) 5361 5222 return -ENOTTY; 5362 5223 5363 5224 pci_dev_lock(dev); ··· 5393 5254 { 5394 5255 int rc; 5395 5256 5396 - if (!dev->reset_fn) 5257 + if (!pci_reset_supported(dev)) 5397 5258 return -ENOTTY; 5398 5259 5399 5260 pci_dev_save_and_disable(dev); ··· 5416 5277 { 5417 5278 int rc; 5418 5279 5419 - if (!dev->reset_fn) 5280 + if (!pci_reset_supported(dev)) 5420 5281 return -ENOTTY; 5421 5282 5422 5283 if (!pci_dev_trylock(dev)) ··· 5644 5505 } 5645 5506 } 5646 5507 5647 - static int pci_slot_reset(struct pci_slot *slot, int probe) 5508 + static int pci_slot_reset(struct pci_slot *slot, bool probe) 5648 5509 { 5649 5510 int rc; 5650 5511 ··· 5672 5533 */ 5673 5534 int pci_probe_reset_slot(struct pci_slot *slot) 5674 5535 { 5675 - return pci_slot_reset(slot, 1); 5536 + return pci_slot_reset(slot, PCI_RESET_PROBE); 5676 5537 } 5677 5538 EXPORT_SYMBOL_GPL(pci_probe_reset_slot); 5678 5539 ··· 5695 5556 { 5696 5557 int rc; 5697 5558 5698 - rc = pci_slot_reset(slot, 1); 5559 + rc = pci_slot_reset(slot, PCI_RESET_PROBE); 5699 5560 if (rc) 5700 5561 return rc; 5701 5562 5702 5563 if (pci_slot_trylock(slot)) { 5703 5564 pci_slot_save_and_disable_locked(slot); 5704 5565 might_sleep(); 5705 - rc = pci_reset_hotplug_slot(slot->hotplug, 0); 5566 + rc = pci_reset_hotplug_slot(slot->hotplug, PCI_RESET_DO_RESET); 5706 5567 pci_slot_restore_locked(slot); 5707 5568 pci_slot_unlock(slot); 5708 5569 } else ··· 5711 5572 return rc; 5712 5573 } 5713 5574 5714 - static int pci_bus_reset(struct pci_bus *bus, int probe) 5575 + static int pci_bus_reset(struct pci_bus *bus, bool probe) 5715 5576 { 5716 5577 int ret; 5717 5578 ··· 5757 5618 goto bus_reset; 5758 5619 5759 5620 list_for_each_entry(slot, &bus->slots, list) 5760 - if (pci_slot_reset(slot, 0)) 5621 + if (pci_slot_reset(slot, PCI_RESET_DO_RESET)) 5761 5622 goto bus_reset; 5762 5623 5763 5624 mutex_unlock(&pci_slot_mutex); 5764 5625 return 0; 5765 5626 bus_reset: 5766 5627 mutex_unlock(&pci_slot_mutex); 5767 - return pci_bus_reset(bridge->subordinate, 0); 5628 + return pci_bus_reset(bridge->subordinate, PCI_RESET_DO_RESET); 5768 5629 } 5769 5630 5770 5631 /** ··· 5775 5636 */ 5776 5637 int pci_probe_reset_bus(struct pci_bus *bus) 5777 5638 { 5778 - return pci_bus_reset(bus, 1); 5639 + return pci_bus_reset(bus, PCI_RESET_PROBE); 5779 5640 } 5780 5641 EXPORT_SYMBOL_GPL(pci_probe_reset_bus); 5781 5642 ··· 5789 5650 { 5790 5651 int rc; 5791 5652 5792 - rc = pci_bus_reset(bus, 1); 5653 + rc = pci_bus_reset(bus, PCI_RESET_PROBE); 5793 5654 if (rc) 5794 5655 return rc; 5795 5656
+20 -4
drivers/pci/pci.h
··· 33 33 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, 34 34 enum pci_mmap_api mmap_api); 35 35 36 - int pci_probe_reset_function(struct pci_dev *dev); 36 + bool pci_reset_supported(struct pci_dev *dev); 37 + void pci_init_reset_methods(struct pci_dev *dev); 37 38 int pci_bridge_secondary_bus_reset(struct pci_dev *dev); 38 39 int pci_bus_error_reset(struct pci_dev *dev); 39 40 ··· 608 607 struct pci_dev_reset_methods { 609 608 u16 vendor; 610 609 u16 device; 611 - int (*reset)(struct pci_dev *dev, int probe); 610 + int (*reset)(struct pci_dev *dev, bool probe); 611 + }; 612 + 613 + struct pci_reset_fn_method { 614 + int (*reset_fn)(struct pci_dev *pdev, bool probe); 615 + char *name; 612 616 }; 613 617 614 618 #ifdef CONFIG_PCI_QUIRKS 615 - int pci_dev_specific_reset(struct pci_dev *dev, int probe); 619 + int pci_dev_specific_reset(struct pci_dev *dev, bool probe); 616 620 #else 617 - static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe) 621 + static inline int pci_dev_specific_reset(struct pci_dev *dev, bool probe) 618 622 { 619 623 return -ENOTTY; 620 624 } ··· 707 701 #ifdef CONFIG_ACPI 708 702 int pci_acpi_program_hp_params(struct pci_dev *dev); 709 703 extern const struct attribute_group pci_dev_acpi_attr_group; 704 + void pci_set_acpi_fwnode(struct pci_dev *dev); 705 + int pci_dev_acpi_reset(struct pci_dev *dev, bool probe); 710 706 #else 707 + static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe) 708 + { 709 + return -ENOTTY; 710 + } 711 + 712 + static inline void pci_set_acpi_fwnode(struct pci_dev *dev) {} 711 713 static inline int pci_acpi_program_hp_params(struct pci_dev *dev) 712 714 { 713 715 return -ENODEV; ··· 725 711 #ifdef CONFIG_PCIEASPM 726 712 extern const struct attribute_group aspm_ctrl_attr_group; 727 713 #endif 714 + 715 + extern const struct attribute_group pci_dev_reset_method_attr_group; 728 716 729 717 #endif /* DRIVERS_PCI_H */
+5 -7
drivers/pci/pcie/aer.c
··· 1407 1407 } 1408 1408 1409 1409 if (type == PCI_EXP_TYPE_RC_EC || type == PCI_EXP_TYPE_RC_END) { 1410 - if (pcie_has_flr(dev)) { 1411 - rc = pcie_flr(dev); 1412 - pci_info(dev, "has been reset (%d)\n", rc); 1413 - } else { 1414 - pci_info(dev, "not reset (no FLR support)\n"); 1415 - rc = -ENOTTY; 1416 - } 1410 + rc = pcie_reset_flr(dev, PCI_RESET_DO_RESET); 1411 + if (!rc) 1412 + pci_info(dev, "has been reset\n"); 1413 + else 1414 + pci_info(dev, "not reset (no FLR support: %d)\n", rc); 1417 1415 } else { 1418 1416 rc = pci_bus_error_reset(dev); 1419 1417 pci_info(dev, "%s Port link has been reset (%d)\n",
+8 -8
drivers/pci/probe.c
··· 19 19 #include <linux/hypervisor.h> 20 20 #include <linux/irqdomain.h> 21 21 #include <linux/pm_runtime.h> 22 + #include <linux/bitfield.h> 22 23 #include "pci.h" 23 24 24 25 #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ ··· 1499 1498 pdev->pcie_cap = pos; 1500 1499 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16); 1501 1500 pdev->pcie_flags_reg = reg16; 1502 - pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, &reg16); 1503 - pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD; 1501 + pci_read_config_dword(pdev, pos + PCI_EXP_DEVCAP, &pdev->devcap); 1502 + pdev->pcie_mpss = FIELD_GET(PCI_EXP_DEVCAP_PAYLOAD, pdev->devcap); 1504 1503 1505 1504 parent = pci_upstream_bridge(pdev); 1506 1505 if (!parent) ··· 1810 1809 dev->error_state = pci_channel_io_normal; 1811 1810 set_pcie_port_type(dev); 1812 1811 1812 + pci_set_of_node(dev); 1813 + pci_set_acpi_fwnode(dev); 1814 + 1813 1815 pci_dev_assign_slot(dev); 1814 1816 1815 1817 /* ··· 1950 1946 default: /* unknown header */ 1951 1947 pci_err(dev, "unknown header type %02x, ignoring device\n", 1952 1948 dev->hdr_type); 1949 + pci_release_of_node(dev); 1953 1950 return -EIO; 1954 1951 1955 1952 bad: ··· 2379 2374 dev->vendor = l & 0xffff; 2380 2375 dev->device = (l >> 16) & 0xffff; 2381 2376 2382 - pci_set_of_node(dev); 2383 - 2384 2377 if (pci_setup_device(dev)) { 2385 - pci_release_of_node(dev); 2386 2378 pci_bus_put(dev->bus); 2387 2379 kfree(dev); 2388 2380 return NULL; ··· 2430 2428 pci_rcec_init(dev); /* Root Complex Event Collector */ 2431 2429 2432 2430 pcie_report_downtraining(dev); 2433 - 2434 - if (pci_probe_reset_function(dev) == 0) 2435 - dev->reset_fn = 1; 2431 + pci_init_reset_methods(dev); 2436 2432 } 2437 2433 2438 2434 /*
+11 -14
drivers/pci/quirks.c
··· 3742 3742 * reset a single function if other methods (e.g. FLR, PM D0->D3) are 3743 3743 * not available. 3744 3744 */ 3745 - static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe) 3745 + static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, bool probe) 3746 3746 { 3747 3747 /* 3748 3748 * http://www.intel.com/content/dam/doc/datasheet/82599-10-gbe-controller-datasheet.pdf ··· 3764 3764 #define NSDE_PWR_STATE 0xd0100 3765 3765 #define IGD_OPERATION_TIMEOUT 10000 /* set timeout 10 seconds */ 3766 3766 3767 - static int reset_ivb_igd(struct pci_dev *dev, int probe) 3767 + static int reset_ivb_igd(struct pci_dev *dev, bool probe) 3768 3768 { 3769 3769 void __iomem *mmio_base; 3770 3770 unsigned long timeout; ··· 3807 3807 } 3808 3808 3809 3809 /* Device-specific reset method for Chelsio T4-based adapters */ 3810 - static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe) 3810 + static int reset_chelsio_generic_dev(struct pci_dev *dev, bool probe) 3811 3811 { 3812 3812 u16 old_command; 3813 3813 u16 msix_flags; ··· 3885 3885 * Chapter 3: NVMe control registers 3886 3886 * Chapter 7.3: Reset behavior 3887 3887 */ 3888 - static int nvme_disable_and_flr(struct pci_dev *dev, int probe) 3888 + static int nvme_disable_and_flr(struct pci_dev *dev, bool probe) 3889 3889 { 3890 3890 void __iomem *bar; 3891 3891 u16 cmd; 3892 3892 u32 cfg; 3893 3893 3894 3894 if (dev->class != PCI_CLASS_STORAGE_EXPRESS || 3895 - !pcie_has_flr(dev) || !pci_resource_start(dev, 0)) 3895 + pcie_reset_flr(dev, PCI_RESET_PROBE) || !pci_resource_start(dev, 0)) 3896 3896 return -ENOTTY; 3897 3897 3898 3898 if (probe) ··· 3959 3959 * device too soon after FLR. A 250ms delay after FLR has heuristically 3960 3960 * proven to produce reliably working results for device assignment cases. 3961 3961 */ 3962 - static int delay_250ms_after_flr(struct pci_dev *dev, int probe) 3962 + static int delay_250ms_after_flr(struct pci_dev *dev, bool probe) 3963 3963 { 3964 - if (!pcie_has_flr(dev)) 3965 - return -ENOTTY; 3966 - 3967 3964 if (probe) 3968 - return 0; 3965 + return pcie_reset_flr(dev, PCI_RESET_PROBE); 3969 3966 3970 - pcie_flr(dev); 3967 + pcie_reset_flr(dev, PCI_RESET_DO_RESET); 3971 3968 3972 3969 msleep(250); 3973 3970 ··· 3979 3982 #define HINIC_OPERATION_TIMEOUT 15000 /* 15 seconds */ 3980 3983 3981 3984 /* Device-specific reset method for Huawei Intelligent NIC virtual functions */ 3982 - static int reset_hinic_vf_dev(struct pci_dev *pdev, int probe) 3985 + static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe) 3983 3986 { 3984 3987 unsigned long timeout; 3985 3988 void __iomem *bar; ··· 4056 4059 * because when a host assigns a device to a guest VM, the host may need 4057 4060 * to reset the device but probably doesn't have a driver for it. 4058 4061 */ 4059 - int pci_dev_specific_reset(struct pci_dev *dev, int probe) 4062 + int pci_dev_specific_reset(struct pci_dev *dev, bool probe) 4060 4063 { 4061 4064 const struct pci_dev_reset_methods *i; 4062 4065 ··· 5666 5669 5667 5670 if (pdev->subsystem_vendor != PCI_VENDOR_ID_LENOVO || 5668 5671 pdev->subsystem_device != 0x222e || 5669 - !pdev->reset_fn) 5672 + !pci_reset_supported(pdev)) 5670 5673 return; 5671 5674 5672 5675 if (pci_enable_device_mem(pdev))
-1
drivers/pci/remove.c
··· 19 19 pci_pme_active(dev, false); 20 20 21 21 if (pci_dev_is_added(dev)) { 22 - dev->reset_fn = 0; 23 22 24 23 device_release_driver(&dev->dev); 25 24 pci_proc_detach_device(dev);
+11 -2
include/linux/pci.h
··· 49 49 PCI_STATUS_SIG_TARGET_ABORT | \ 50 50 PCI_STATUS_PARITY) 51 51 52 + /* Number of reset methods used in pci_reset_fn_methods array in pci.c */ 53 + #define PCI_NUM_RESET_METHODS 7 54 + 55 + #define PCI_RESET_PROBE true 56 + #define PCI_RESET_DO_RESET false 57 + 52 58 /* 53 59 * The PCI interface treats multi-function devices as independent 54 60 * devices. The slot/function address of each device is encoded ··· 339 333 struct rcec_ea *rcec_ea; /* RCEC cached endpoint association */ 340 334 struct pci_dev *rcec; /* Associated RCEC device */ 341 335 #endif 336 + u32 devcap; /* PCIe Device Capabilities */ 342 337 u8 pcie_cap; /* PCIe capability offset */ 343 338 u8 msi_cap; /* MSI capability offset */ 344 339 u8 msix_cap; /* MSI-X capability offset */ ··· 435 428 unsigned int state_saved:1; 436 429 unsigned int is_physfn:1; 437 430 unsigned int is_virtfn:1; 438 - unsigned int reset_fn:1; 439 431 unsigned int is_hotplug_bridge:1; 440 432 unsigned int shpc_managed:1; /* SHPC owned by shpchp */ 441 433 unsigned int is_thunderbolt:1; /* Thunderbolt controller */ ··· 512 506 char *driver_override; /* Driver name to force a match */ 513 507 514 508 unsigned long priv_flags; /* Private flags for the PCI driver */ 509 + 510 + /* These methods index pci_reset_fn_methods[] */ 511 + u8 reset_methods[PCI_NUM_RESET_METHODS]; /* In priority order */ 515 512 }; 516 513 517 514 static inline struct pci_dev *pci_physfn(struct pci_dev *dev) ··· 1238 1229 enum pci_bus_speed *speed, 1239 1230 enum pcie_link_width *width); 1240 1231 void pcie_print_link_status(struct pci_dev *dev); 1241 - bool pcie_has_flr(struct pci_dev *dev); 1232 + int pcie_reset_flr(struct pci_dev *dev, bool probe); 1242 1233 int pcie_flr(struct pci_dev *dev); 1243 1234 int __pci_reset_function_locked(struct pci_dev *dev); 1244 1235 int pci_reset_function(struct pci_dev *dev);
+1 -1
include/linux/pci_hotplug.h
··· 44 44 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value); 45 45 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value); 46 46 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value); 47 - int (*reset_slot) (struct hotplug_slot *slot, int probe); 47 + int (*reset_slot) (struct hotplug_slot *slot, bool probe); 48 48 }; 49 49 50 50 /**