export pcie_flr and remove copies of it in drivers
Subsystems (8)
Hi all,
this exports the PCI layer pcie_flr helper, and removes various opencoded copies of it.
PATCH 1/7 PCI: export pcie_flr
Currently we opencode the FLR sequence in lots of place, export a core helper instead. We split out the probing for FLR support as all the non-core callers already know their hardware.
--- drivers/pci/pci.c | 34 +++++++++++++++++++++++++--------- include/linux/pci.h | 1 + 2 files changed, 26 insertions(+), 9 deletions(-)
drivers/pci/pci.c +25 -9
@@ -3773,24 +3773,38 @@ static void pci_flr_wait(struct pci_dev *dev) (i - 1) * 100); } -static int pcie_flr (struct pci_dev *dev,int probe) +/** +* pcie_has_flr - check if a device supports function level resets +* @dev: device to check +* +* Returns true if the device advertises support for PCIe function level +* resets. +*/ +static bool pcie_has_flr (struct pci_dev *dev) {u32 cap;pcie_capability_read_dword (dev,PCI_EXP_DEVCAP , &cap); -if (!(cap &PCI_EXP_DEVCAP_FLR )) -return -ENOTTY ; - -if (probe) -return 0 ; +return cap &PCI_EXP_DEVCAP_FLR ; +} +/** +* pcie_flr - initiate a PCIe function level reset +* @dev: device to reset +* +* Initiate a function level reset on @dev. The caller should ensure the +* device supports FLR before calling this function, e.g. by using the +* pcie_has_flr helper. +*/ +void pcie_flr (struct pci_dev *dev) +{if (!pci_wait_for_pending_transaction (dev))dev_err (&dev->dev,"timed out waiting for pending transaction; performing function level reset anyway\n" );pcie_capability_set_word (dev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_BCR_FLR );pci_flr_wait (dev); -return 0 ; } +EXPORT_SYMBOL_GPL (pcie_flr);static int pci_af_flr (struct pci_dev *dev,int probe) {
@@ -3971,9 +3985,11 @@ static int __pci_dev_reset(struct pci_dev *dev, int probe)if (rc != -ENOTTY ) goto done; - rc =pcie_flr (dev, probe); -if (rc != -ENOTTY ) +if (pcie_has_flr (dev)) { +pcie_flr (dev); + rc =0 ; goto done; + } rc =pci_af_flr (dev, probe);if (rc != -ENOTTY )
include/linux/pci.h +1 -0
@@ -1052,6 +1052,7 @@ int pcie_get_mps(struct pci_dev *dev);int pcie_set_mps (struct pci_dev *dev,int mps);int pcie_get_minimum_link (struct pci_dev *dev,enum pci_bus_speed *speed,enum pcie_link_width *width); +void pcie_flr (struct pci_dev *dev);int __pci_reset_function (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);
Signature · 1 line
2.11.0
Re: [PATCH 1/7] PCI: export pcie_flr
[+cc Alex]
Quoted 36 lines · Christoph Hellwig
Currently we opencode the FLR sequence in lots of place, export a core helper instead. We split out the probing for FLR support as all the non-core callers already know their hardware.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/pci/pci.c | 34 +++++++++++++++++++++++++--------- include/linux/pci.h | 1 + 2 files changed, 26 insertions(+), 9 deletions(-)drivers/pci/pci.c +8
-6@@ -3773,24 +3773,38 @@ static void pci_flr_wait(struct pci_dev *dev) (i - 1) * 100); } -static int pcie_flr (struct pci_dev *dev,int probe) +/** +* pcie_has_flr - check if a device supports function level resets +* @dev: device to check +* +* Returns true if the device advertises support for PCIe function level +* resets. +*/ +static bool pcie_has_flr (struct pci_dev *dev) {u32 cap;pcie_capability_read_dword (dev,PCI_EXP_DEVCAP , &cap); -if (!(cap &PCI_EXP_DEVCAP_FLR )) -return -ENOTTY ; - -if (probe) -return 0 ;
drivers/pci/pci.c static void pci_flr_wait(struct pci_dev *dev) · line 3797
Quoted 10 lines
drivers/pci/pci.c +9
-0+return cap &PCI_EXP_DEVCAP_FLR ; +} +/** +* pcie_flr - initiate a PCIe function level reset +* @dev: device to reset +* +* Initiate a function level reset on @dev. The caller should ensure the +* device supports FLR before calling this function, e.g. by using the +* pcie_has_flr helper.
s/pcie_has_flr/pcie_has_flr()/
Quoted 15 lines
drivers/pci/pci.c +4
-1+*/ +void pcie_flr (struct pci_dev *dev) +{if (!pci_wait_for_pending_transaction (dev))dev_err (&dev->dev,"timed out waiting for pending transaction; performing function level reset anyway\n" );pcie_capability_set_word (dev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_BCR_FLR );pci_flr_wait (dev); -return 0 ; } +EXPORT_SYMBOL_GPL (pcie_flr);static int pci_af_flr (struct pci_dev *dev,int probe) {
drivers/pci/pci.c static int __pci_dev_reset(struct pci_dev *dev, int probe) · line 3992
Quoted 10 lines
drivers/pci/pci.c +4
-2@@ -3971,9 +3985,11 @@ static int __pci_dev_reset(struct pci_dev *dev, int probe)if (rc != -ENOTTY ) goto done; - rc =pcie_flr (dev, probe); -if (rc != -ENOTTY ) +if (pcie_has_flr (dev)) { +pcie_flr (dev); + rc =0 ; goto done; + }
This performs an FLR (if supported) always, regardless of "probe". I think it should look something like this instead:
if (pcie_has_flr(dev)) {
if (!probe)
pcie_flr(dev);
rc = 0;
goto done;
}Quoted 17 lines
drivers/pci/pci.c +0
-0rc =pci_af_flr (dev, probe);if (rc != -ENOTTY )include/linux/pci.h +1
-0@@ -1052,6 +1052,7 @@ int pcie_get_mps(struct pci_dev *dev);int pcie_set_mps (struct pci_dev *dev,int mps);int pcie_get_minimum_link (struct pci_dev *dev,enum pci_bus_speed *speed,enum pcie_link_width *width); +void pcie_flr (struct pci_dev *dev);int __pci_reset_function (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);Signature · 1 line
2.11.0
Re: [PATCH 1/7] PCI: export pcie_flr
Quoted 1 line
s/pcie_has_flr/pcie_has_flr()/
Ok.
Quoted 9 lines
This performs an FLR (if supported) always, regardless of "probe". I think it should look something like this instead:
if (pcie_has_flr(dev)) { if (!probe) pcie_flr(dev); rc = 0; goto done; }
Indeed!
PATCH 2/7 PCI: call pcie_flr from reset_intel_82599_sfp_virtfn
In reply to Christoph HellwigThe 82599 quirk contained an outdated copy of the FLR code.
--- drivers/pci/quirks.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/pci/quirks.c +4 -12
@@ -3642,19 +3642,11 @@ static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe)* * The 82599 supports FLR on VFs, but FLR support is reported only * in the PF DEVCAP (sec 9.3.10.4), not in the VF DEVCAP (sec 9.5). -* Therefore, we can't use pcie_flr(), which checks the VF DEVCAP. +* Thus we must call pcie_flr directly without first checking if it is +* supported. */ - -if (probe) -return 0 ; - -if (!pci_wait_for_pending_transaction (dev)) -dev_err (&dev->dev,"transaction is not cleared; proceeding with reset anyway\n" ); - -pcie_capability_set_word (dev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_BCR_FLR ); - -msleep (100 ); - +if (!probe) +pcie_flr (dev);return 0 ; }
Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/7 PCI: call pcie_flr from reset_chelsio_generic_dev
In reply to Christoph HellwigInstead of copy & pasting and old version of the code.
--- drivers/pci/quirks.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/pci/quirks.c +1 -14
@@ -3751,20 +3751,7 @@ static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe)PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL); -/* -* Start of pcie_flr() code sequence. This reset code is a copy of -* the guts of pcie_flr() because that's not an exported function. -*/ - -if (!pci_wait_for_pending_transaction (dev)) -dev_err (&dev->dev,"transaction is not cleared; proceeding with reset anyway\n" ); - -pcie_capability_set_word (dev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_BCR_FLR ); -msleep (100 ); - -/* -* End of pcie_flr() code sequence. -*/ +pcie_flr (dev);/* * Restore the configuration information (BAR values, etc.) including
Signature · 1 line
2.11.0
PATCH 4/7 ixgbe: use pcie_flr instead of duplicating it
In reply to Christoph Hellwig--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -14
@@ -7112,18 +7112,6 @@ static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) }#ifdef CONFIG_PCI_IOV -static inline void ixgbe_issue_vf_flr (struct ixgbe_adapter *adapter, -struct pci_dev *vfdev) -{ -if (!pci_wait_for_pending_transaction (vfdev)) -e_dev_warn ("Issuing VFLR with pending transactions\n" ); - -e_dev_err ("Issuing VFLR for VF %s\n" ,pci_name (vfdev)); -pcie_capability_set_word (vfdev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_BCR_FLR ); - -msleep (100 ); -} -static void ixgbe_check_for_bad_vf (struct ixgbe_adapter *adapter) {struct ixgbe_hw *hw = &adapter->hw;
@@ -7156,7 +7144,7 @@ static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)pci_read_config_word (vfdev,PCI_STATUS , &status_reg);if (status_reg !=IXGBE_FAILED_READ_CFG_WORD && status_reg &PCI_STATUS_REC_MASTER_ABORT ) -ixgbe_issue_vf_flr (adapter, vfdev); +pcie_flr (vfdev); } }
@@ -10244,7 +10232,7 @@ static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,* VFLR. Just clean up the AER in that case. */ if (vfdev) { -ixgbe_issue_vf_flr (adapter, vfdev); +pcie_flr (vfdev);/* Free device reference count */ pci_dev_put (vfdev); }
Signature · 1 line
2.11.0
Re: [PATCH 4/7] ixgbe: use pcie_flr instead of duplicating it
Quoted 4 lines · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>---
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 16 ++--------------1 file changed, 2 insertions(+), 14 deletions(-)
Sorry for the late ACK.
PATCH 5/7 IB/hfi1: use pcie_flr instead of duplicating it
In reply to Christoph Hellwig--- drivers/infiniband/hw/hfi1/chip.c | 4 ++-- drivers/infiniband/hw/hfi1/hfi.h | 1 - drivers/infiniband/hw/hfi1/pcie.c | 30 ------------------------------ 3 files changed, 2 insertions(+), 33 deletions(-)
drivers/infiniband/hw/hfi1/chip.c +2 -2
@@ -13610,14 +13610,14 @@ static void init_chip(struct hfi1_devdata *dd)dd_dev_info (dd,"Resetting CSRs with FLR\n" );/* do the FLR, the DC reset will remain */ -hfi1_pcie_flr (dd); +pcie_flr (dd->pcidev);/* restore command and BARs */ restore_pci_variables (dd);if (is_ax (dd)) {dd_dev_info (dd,"Resetting CSRs with FLR\n" ); -hfi1_pcie_flr (dd); +pcie_flr (dd->pcidev);restore_pci_variables (dd); } }else {
drivers/infiniband/hw/hfi1/hfi.h +0 -1
@@ -1764,7 +1764,6 @@ int hfi1_pcie_init(struct pci_dev *, const struct pci_device_id *);void hfi1_pcie_cleanup (struct pci_dev *);int hfi1_pcie_ddinit (struct hfi1_devdata *,struct pci_dev *);void hfi1_pcie_ddcleanup (struct hfi1_devdata *); -void hfi1_pcie_flr (struct hfi1_devdata *);int pcie_speeds (struct hfi1_devdata *);void request_msix (struct hfi1_devdata *,u32 *,struct hfi1_msix_entry *);void hfi1_enable_intx (struct pci_dev *);
drivers/infiniband/hw/hfi1/pcie.c +0 -30
@@ -240,36 +240,6 @@ void hfi1_pcie_ddcleanup(struct hfi1_devdata *dd)iounmap (dd->piobase); } -/* -* Do a Function Level Reset (FLR) on the device. -* Based on static function drivers/pci/pci.c:pcie_flr(). -*/ -void hfi1_pcie_flr (struct hfi1_devdata *dd) -{ -int i; -u16 status; - -/* no need to check for the capability - we know the device has it */ - -/* wait for Transaction Pending bit to clear, at most a few ms */ -for (i =0 ; i <4 ; i++) { -if (i) -msleep ((1 << (i -1 )) *100 ); - -pcie_capability_read_word (dd->pcidev,PCI_EXP_DEVSTA , &status); -if (!(status &PCI_EXP_DEVSTA_TRPND )) - goto clear; - } - -dd_dev_err (dd,"Transaction Pending bit is not clearing, proceeding with reset anyway\n" ); - -clear: -pcie_capability_set_word (dd->pcidev,PCI_EXP_DEVCTL , -PCI_EXP_DEVCTL_BCR_FLR ); -/* PCIe spec requires the function to be back within 100ms */ -msleep (100 ); -} -static void msix_setup (struct hfi1_devdata *dd,int pos,u32 *msixcnt,struct hfi1_msix_entry *hfi1_msix_entry) {
Signature · 1 line
2.11.0
PATCH 6/7 crypto: qat: use pcie_flr instead of duplicating it
In reply to Christoph Hellwig--- drivers/crypto/qat/qat_common/adf_aer.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/crypto/qat/qat_common/adf_aer.c +1 -14
@@ -109,20 +109,7 @@ EXPORT_SYMBOL_GPL(adf_reset_sbr);void adf_reset_flr (struct adf_accel_dev *accel_dev) { -struct pci_dev *pdev =accel_to_pci_dev (accel_dev); -u16 control =0 ; -int pos =0 ; - -dev_info (&GET_DEV (accel_dev),"Function level reset\n" ); - pos =pci_pcie_cap (pdev); -if (!pos) { -dev_err (&GET_DEV (accel_dev),"Restart device failed\n" ); -return ; - } -pci_read_config_word (pdev, pos +PCI_EXP_DEVCTL , &control); - control |=PCI_EXP_DEVCTL_BCR_FLR ; -pci_write_config_word (pdev, pos +PCI_EXP_DEVCTL , control); -msleep (100 ); +pcie_flr (accel_to_pci_dev (accel_dev)); }EXPORT_SYMBOL_GPL (adf_reset_flr);
Signature · 1 line
2.11.0
PATCH 7/7 liquidio: use pcie_flr instead of duplicating it
In reply to Christoph Hellwig--- drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +1 -14
@@ -899,20 +899,7 @@ static void octeon_pci_flr(struct octeon_device *oct)pci_write_config_word (oct->pci_dev,PCI_COMMAND ,PCI_COMMAND_INTX_DISABLE ); -/* Wait for Transaction Pending bit clean */ -msleep (100 ); -pcie_capability_read_word (oct->pci_dev,PCI_EXP_DEVSTA , &status); -if (status &PCI_EXP_DEVSTA_TRPND ) { -dev_info (&oct->pci_dev->dev,"Function reset incomplete after 100ms, sleeping for 5 seconds\n" ); -ssleep (5 ); -pcie_capability_read_word (oct->pci_dev,PCI_EXP_DEVSTA , - &status); -if (status &PCI_EXP_DEVSTA_TRPND ) -dev_info (&oct->pci_dev->dev,"Function reset still incomplete after 5s, reset anyway\n" ); - } -pcie_capability_set_word (oct->pci_dev,PCI_EXP_DEVCTL , -PCI_EXP_DEVCTL_BCR_FLR ); -mdelay (100 ); +pcie_flr (oct->pci_dev);pci_cfg_access_unlock (oct->pci_dev);
Signature · 1 line
2.11.0
Bjorn Helgaas
Acked-byQuoted 4 lines · Christoph Hellwig
Hi all,
this exports the PCI layer
pcie_flrhelper, and removes various opencoded copies of it.
Looks good to me (except the comment on probe). If you want to apply the whole series via netdev or some non-PCI tree, here's my ack for the drivers/pci parts, assuming the probe thing is resolved:
Otherwise, I'd be glad to take the series given acks for the non-PCI parts. Just let me know.
Bjorn
Bjorn Helgaas
maintainerQuoted 6 lines · Bjorn Helgaas
Quoted 4 lines · Christoph Hellwig
Hi all,
this exports the PCI layer
pcie_flrhelper, and removes various opencoded copies of it.
Quoted 8 lines
Looks good to me (except the comment on probe). If you want to apply the whole series via netdev or some non-PCI tree, here's my ack for the
drivers/pciparts, assuming the probe thing is resolved:Acked-by Bjorn Helgaas <[email protected]>Otherwise, I'd be glad to take the series given acks for the non-PCI parts. Just let me know.
I do already have a patch (c5e4f0192ad2 ("PCI: Avoid FLR for Intel 82579 NICs")) on my pci/virtualization branch that touches pcie_flr() and will conflict with this one.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Bjorn Helgaas
Quoted 2 lines
Otherwise, I'd be glad to take the series given acks for the non-PCI parts. Just let me know.
I do already have a patch (
c5e4f0192ad2("PCI: Avoid FLR for Intel 82579 NICs")) on my pci/virtualization branch that touchespcie_flr()and will conflict with this one.
I'll take a look and will resend on top of that branch.
Quoted 8 lines · Bjorn Helgaas
Looks good to me (except the comment on probe). If you want to apply the whole series via netdev or some non-PCI tree, here's my ack for the
drivers/pciparts, assuming the probe thing is resolved:Acked-by Bjorn Helgaas <[email protected]>Otherwise, I'd be glad to take the series given acks for the non-PCI parts. Just let me know.
I guess the best would be if you take the first three patches (once resent) for the PCI tree for 4.12, then we can do the other patches in the next merge window.