igc: Add pcie error handler support
Subsystems (2)
PATCH 1/1 igc: Add pcie error handler support
Add pcie error detection, slot reset and resume capability
--- drivers/net/ethernet/intel/igc/igc_main.c | 105 ++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+)
drivers/net/ethernet/intel/igc/igc_main.c +105 -0
@@ -5076,6 +5076,110 @@ static void igc_shutdown(struct pci_dev *pdev) } } +/** +* igc_io_error_detected - called when PCI error is detected +* @pdev: Pointer to PCI device +* @state: The current pci connection state +* +* This function is called after a PCI bus error affecting +* this device has been detected. +**/ +static pci_ers_result_t igc_io_error_detected (struct pci_dev *pdev, +pci_channel_state_t state) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev); + +netif_device_detach (netdev); + +if (state == pci_channel_io_perm_failure) +return PCI_ERS_RESULT_DISCONNECT ; + +if (netif_running (netdev)) +igc_down (adapter); +pci_disable_device (pdev); + +/* Request a slot slot reset. */ +return PCI_ERS_RESULT_NEED_RESET ; +} + +/** +* igc_io_slot_reset - called after the pci bus has been reset. +* @pdev: Pointer to PCI device +* +* Restart the card from scratch, as if from a cold-boot. Implementation +* resembles the first-half of the igc_resume routine. +**/ +static pci_ers_result_t igc_io_slot_reset (struct pci_dev *pdev) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev); +struct igc_hw *hw = &adapter->hw; +pci_ers_result_t result; + +if (pci_enable_device_mem (pdev)) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after reset.\n" ); + result =PCI_ERS_RESULT_DISCONNECT ; + }else { +pci_set_master (pdev); +pci_restore_state (pdev); +pci_save_state (pdev); + +pci_enable_wake (pdev, PCI_D3hot,0 ); +pci_enable_wake (pdev, PCI_D3cold,0 ); + +/* In case of PCI error, adapter lose its HW address +* so we should re-assign it here. +*/ + hw->hw_addr = adapter->io_addr; + +igc_reset (adapter); +wr32 (IGC_WUS , ~0 ); + result =PCI_ERS_RESULT_RECOVERED ; + } + +return result; +} + +/** +* igc_io_resume - called when traffic can start flowing again. +* @pdev: Pointer to PCI device +* +* This callback is called when the error recovery driver tells us that +* its OK to resume normal operation. Implementation resembles the +* second-half of the igc_resume routine. +*/ +static void igc_io_resume (struct pci_dev *pdev) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev); +u32 err =0 ; + +rtnl_lock (); +if (netif_running (netdev)) { + err =igc_open (netdev); +if (err) { +dev_err (&pdev->dev,"igic_open failed after reset\n" ); +return ; + } + } + +netif_device_attach (netdev); + +/* let the f/w know that the h/w is now under the control of the +* driver. +*/ +igc_get_hw_control (adapter); +rtnl_unlock (); +} + +static const struct pci_error_handlers igc_err_handler = { + .error_detected = igc_io_error_detected, + .slot_reset = igc_io_slot_reset, + .resume = igc_io_resume, +}; +#ifdef CONFIG_PM static const struct dev_pm_ops igc_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(igc_suspend, igc_resume)
@@ -5093,6 +5197,7 @@ static struct pci_driver igc_driver = { .driver.pm = &igc_pm_ops, #endif .shutdown = igc_shutdown, + .err_handler = &igc_err_handler, };/**
Signature · 1 line
2.11.0
PATCH 1/1 igc: Add pcie error handler support
Dear Sasha,
Thank you for your patch set.
Quoted 1 line · Sasha Neftin
Add pcie error detection, slot reset and resume capability
Tested how?
Quoted 10 lines
Signed-off-by Sasha Neftin <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 105 ++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+)drivers/net/ethernet/intel/igc/igc_main.c +0
-0
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5082
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0@@ -5076,6 +5076,110 @@ static void igc_shutdown(struct pci_dev *pdev) } } +/** +* igc_io_error_detected - called when PCI error is detected +* @pdev: Pointer to PCI device +* @state: The current pci connection state
PCI
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5085
Quoted 3 lines
drivers/net/ethernet/intel/igc/igc_main.c +3
-0+* +* This function is called after a PCI bus error affecting +* this device has been detected.
Document the two possible return codes?
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c +7
-0+**/ +static pci_ers_result_t igc_io_error_detected (struct pci_dev *pdev, +pci_channel_state_t state) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev); +
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5102
Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_main.c +10
-0+netif_device_detach (netdev); + +if (state == pci_channel_io_perm_failure) +return PCI_ERS_RESULT_DISCONNECT ; + +if (netif_running (netdev)) +igc_down (adapter); +pci_disable_device (pdev); + +/* Request a slot slot reset. */
One slot?
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5107
Quoted 5 lines
drivers/net/ethernet/intel/igc/igc_main.c +5
-0+return PCI_ERS_RESULT_NEED_RESET ; +} + +/** +* igc_io_slot_reset - called after the pci bus has been reset.
PCI
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5111
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0+* @pdev: Pointer to PCI device +* +* Restart the card from scratch, as if from a cold-boot. Implementation +* resembles the first-half of the igc_resume routine.
Shouldn?t the common code be factored out then?
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5122
Quoted 11 lines
drivers/net/ethernet/intel/igc/igc_main.c +11
-0+**/ +static pci_ers_result_t igc_io_slot_reset (struct pci_dev *pdev) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev); +struct igc_hw *hw = &adapter->hw; +pci_ers_result_t result; + +if (pci_enable_device_mem (pdev)) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after reset.\n" );
*Could not*, so it?s clear, it was tried, and not a policy decision.
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5132
Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_main.c +10
-0+ result =PCI_ERS_RESULT_DISCONNECT ; + }else { +pci_set_master (pdev); +pci_restore_state (pdev); +pci_save_state (pdev); + +pci_enable_wake (pdev, PCI_D3hot,0 ); +pci_enable_wake (pdev, PCI_D3cold,0 ); + +/* In case of PCI error, adapter lose its HW address
lose*s*
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5142
Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_main.c +10
-0+* so we should re-assign it here. +*/ + hw->hw_addr = adapter->io_addr; + +igc_reset (adapter); +wr32 (IGC_WUS , ~0 ); + result =PCI_ERS_RESULT_RECOVERED ; + } + +return result;
You can get rid of the if-else statement, by returning in the if branch, and use the else branch as the follow-on(?). Then you can return the result directly too, and even remove the variable result.
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5146
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0+} + +/** +* igc_io_resume - called when traffic can start flowing again.
start to flow
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_main.c +6
-0+* @pdev: Pointer to PCI device +* +* This callback is called when the error recovery driver tells us that +* its OK to resume normal operation. Implementation resembles the +* second-half of the igc_resume routine. +*/
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5162
Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_main.c +10
-0+static void igc_io_resume (struct pci_dev *pdev) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev); +u32 err =0 ; + +rtnl_lock (); +if (netif_running (netdev)) { + err =igc_open (netdev); +if (err) {
Use if (igc_open(netdev)) {, and remove variable err?
Quoted 25 lines
drivers/net/ethernet/intel/igc/igc_main.c +20
-0+dev_err (&pdev->dev,"igic_open failed after reset\n" ); +return ; + } + } + +netif_device_attach (netdev); + +/* let the f/w know that the h/w is now under the control of the +* driver. +*/ +igc_get_hw_control (adapter); +rtnl_unlock (); +} + +static const struct pci_error_handlers igc_err_handler = { + .error_detected = igc_io_error_detected, + .slot_reset = igc_io_slot_reset, + .resume = igc_io_resume, +}; +#ifdef CONFIG_PM static const struct dev_pm_ops igc_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(igc_suspend, igc_resume)
drivers/net/ethernet/intel/igc/igc_main.c static struct pci_driver igc_driver = { · line 5203
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c +1
-0@@ -5093,6 +5197,7 @@ static struct pci_driver igc_driver = { .driver.pm = &igc_pm_ops, #endif .shutdown = igc_shutdown, + .err_handler = &igc_err_handler, };/**
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5174 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20200127/b35d9905/attachment.p7s>
Neftin
PATCH 1/1 igc: Add pcie error handler support
Quoted 11 lines · Paul Menzel
Dear Sasha,
Thank you for your patch set.
Quoted 1 line · Sasha Neftin
Add pcie error detection, slot reset and resume capability
Tested how?
Tested on the platform with error-prone PCIe slot and system has been recovered. To more testing, I would recommend using peripheral equipment. Lecroy's PCIe test board could be a good option.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Sasha Neftin <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 105 ++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+)drivers/net/ethernet/intel/igc/igc_main.c +0
-0@@ -5076,6 +5076,110 @@ static void igc_shutdown(struct pci_dev *pdev) } }
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5082
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0+/** +* igc_io_error_detected - called when PCI error is detected +* @pdev: Pointer to PCI device +* @state: The current pci connection state PCI
good. I will change.
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5085
Quoted 3 lines
drivers/net/ethernet/intel/igc/igc_main.c +3
-0+* +* This function is called after a PCI bus error affecting +* this device has been detected. Document the two possible return codes?
I will elaborate on the comment.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/intel/igc/igc_main.c +11
-0+**/ +static pci_ers_result_t igc_io_error_detected (struct pci_dev *pdev, +pci_channel_state_t state) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev); + +netif_device_detach (netdev); + +if (state == pci_channel_io_perm_failure) +return PCI_ERS_RESULT_DISCONNECT ;
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5102
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_main.c +6
-0+ +if (netif_running (netdev)) +igc_down (adapter); +pci_disable_device (pdev); + +/* Request a slot slot reset. */ One slot?
yes, typo.
Quoted 8 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5107
Quoted 5 lines
drivers/net/ethernet/intel/igc/igc_main.c +5
-0+return PCI_ERS_RESULT_NEED_RESET ; +} + +/** +* igc_io_slot_reset - called after the pci bus has been reset. PCI
ok.
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5111
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0+* @pdev: Pointer to PCI device +* +* Restart the card from scratch, as if from a cold-boot. Implementation +* resembles the first-half of the igc_resume routine. Shouldn?t the common code be factored out then?
I prefer stay align with our legacy code in other drivers.
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/intel/igc/igc_main.c +5
-0+**/ +static pci_ers_result_t igc_io_slot_reset (struct pci_dev *pdev) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev);
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5122
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_main.c +6
-0+struct igc_hw *hw = &adapter->hw; +pci_ers_result_t result; + +if (pci_enable_device_mem (pdev)) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after reset.\n" );*Could not*, so it?s clear, it was tried, and not a policy decision.
ok.
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0+ result =PCI_ERS_RESULT_DISCONNECT ; + }else { +pci_set_master (pdev); +pci_restore_state (pdev);
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5132
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_main.c +6
-0+pci_save_state (pdev); + +pci_enable_wake (pdev, PCI_D3hot,0 ); +pci_enable_wake (pdev, PCI_D3cold,0 ); + +/* In case of PCI error, adapter lose its HW address lose*s*
ok.
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_main.c +6
-0+* so we should re-assign it here. +*/ + hw->hw_addr = adapter->io_addr; + +igc_reset (adapter); +wr32 (IGC_WUS , ~0 );
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5142
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0+ result =PCI_ERS_RESULT_RECOVERED ; + } + +return result;You can get rid of the if-else statement, by returning in the if branch, and use the else branch as the follow-on(?). Then you can return the result directly too, and even remove the variable
result.
I prefer stay with a legacy code to align with other ours drivers.
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5146
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_main.c +4
-0+} + +/** +* igc_io_resume - called when traffic can start flowing again. start to flow
ok, thanks.
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_main.c +10
-0+* @pdev: Pointer to PCI device +* +* This callback is called when the error recovery driver tells us that +* its OK to resume normal operation. Implementation resembles the +* second-half of the igc_resume routine. +*/ +static void igc_io_resume (struct pci_dev *pdev) +{ +struct net_device *netdev =pci_get_drvdata (pdev); +struct igc_adapter *adapter =netdev_priv (netdev);
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_main.c static void igc_shutdown(struct pci_dev *pdev) · line 5162
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_main.c +6
-0+u32 err =0 ; + +rtnl_lock (); +if (netif_running (netdev)) { + err =igc_open (netdev); +if (err) {Use
if (igc_open(netdev)) {, and remove variableerr?
good idea. thanks
Quoted 30 lines
Quoted 30 lines
drivers/net/ethernet/intel/igc/igc_main.c +21
-0+dev_err (&pdev->dev,"igic_open failed after reset\n" ); +return ; + } + } + +netif_device_attach (netdev); + +/* let the f/w know that the h/w is now under the control of the +* driver. +*/ +igc_get_hw_control (adapter); +rtnl_unlock (); +} + +static const struct pci_error_handlers igc_err_handler = { + .error_detected = igc_io_error_detected, + .slot_reset = igc_io_slot_reset, + .resume = igc_io_resume, +}; +#ifdef CONFIG_PM static const struct dev_pm_ops igc_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(igc_suspend, igc_resume)@@ -5093,6 +5197,7 @@ static struct pci_driver igc_driver = { .driver.pm = &igc_pm_ops, #endif .shutdown = igc_shutdown, + .err_handler = &igc_err_handler, };
Quoted 3 lines
drivers/net/ethernet/intel/igc/igc_main.c static struct pci_driver igc_driver = { · line 5203
Quoted 2 lines
drivers/net/ethernet/intel/igc/igc_main.c +0
-0/**
Paul, thanks for your feedback - I will submit v2 and address your comments.