ixgbe: fix FCoE/XDP issues and PCI reset handling
Subsystems (3)
v2 cover ixgbe: fix FCoE/XDP issues and PCI reset handling
This series fixes several ixgbe error and reset codepaths.
The first three patches are prerequisite fixes that make sure that the driver does not access hardware during the reset time when it is unavailable. These add the required availability checks etc.
The final patch adds missing handlers for PCI function reset through sysfs in the manner that is safe for ixgbe. It implements the PCI reset prepare and completion callbacks to quiesce and reinitialize the adapter. This prevents TX queue timeouts and other related problems caused by inconsistent hardware state after a sysfs-triggered PCI reset.
Previous version:
https://lore.kernel.org/netdev/[email protected]/v1->v2: Almost complete rework of the series to ensure safe
reset procedure
Sergey Temerkhanov (4):
ixgbe: Refactor device operations to check whether netdev is available
ixgbe: Fix FCoE refcount taking for unsupported adapters
ixgbe: Restore previous XDP program on ixgbe_setup_tc() failure
ixgbe: Implement PCI reset handler
drivers/net/ethernet/intel/ixgbe/ixgbe.h | 6 + .../net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c | 13 +- .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 34 +-- drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 42 +++- drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.h | 1 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 193 +++++++++++++++++- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 4 +- 7 files changed, 262 insertions(+), 31 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/4 ixgbe: Refactor device operations to check whether netdev is available
Refactor several ixgbe driver operations to check whether the netdev they operate on is enabled. This will allow the system to get synchronized, for example, during the PCI resets.
--- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 5 +++ .../net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c | 13 +++++- .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 34 +++++++++------ drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 29 +++++++++---- drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.h | 1 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 42 +++++++++++++++++-- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 4 +- 7 files changed, 101 insertions(+), 27 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +5 -0
@@ -955,6 +955,11 @@ extern char ixgbe_driver_name[];extern char ixgbe_default_device_descr[];#endif /* IXGBE_FCOE */ +static inline bool ixgbe_netif_running (struct net_device *netdev) +{ +return netif_running (netdev) &&netif_device_present (netdev); +} +int ixgbe_open (struct net_device *netdev);int ixgbe_close (struct net_device *netdev);void ixgbe_up (struct ixgbe_adapter *adapter);
drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c +11 -2
@@ -277,17 +277,23 @@ static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,static void ixgbe_dcbnl_devreset (struct net_device *dev) {struct ixgbe_adapter *adapter =ixgbe_from_netdev (dev); +bool running; + +if (!netif_device_present (dev)) +return ; + + running =netif_running (dev);while (test_and_set_bit (__IXGBE_RESETTING, &adapter->state))usleep_range (1000 ,2000 ); -if (netif_running (dev)) +if (running) dev->netdev_ops->ndo_stop (dev);ixgbe_clear_interrupt_scheme (adapter);ixgbe_init_interrupt_scheme (adapter); -if (netif_running (dev)) +if (running) dev->netdev_ops->ndo_open (dev);clear_bit (__IXGBE_RESETTING, &adapter->state);
@@ -515,6 +521,9 @@ static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,if (!(adapter->dcbx_cap &DCB_CAP_DCBX_VER_IEEE ))return -EINVAL ; +if (!netif_device_present (dev)) +return -ENETDOWN ; +if (!adapter->ixgbe_ieee_ets) { adapter->ixgbe_ieee_ets = kmalloc_obj(struct ieee_ets);if (!adapter->ixgbe_ieee_ets)
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +21 -13
@@ -468,6 +468,9 @@ static int ixgbe_set_link_ksettings(struct net_device *netdev,u32 advertised, old;int err =0 ; +if (!netif_device_present (netdev)) +return -ENETDOWN ; +if ((hw->phy.media_type == ixgbe_media_type_copper) || (hw->phy.multispeed_fiber)) {/*
@@ -578,9 +581,9 @@ static void ixgbe_set_pauseparam_finalize(struct net_device *netdev,/* If the thing changed then we'll update and use new autoneg. */ if (memcmp (fc, &hw->fc,sizeof (*fc))) { hw->fc = *fc; -if (netif_running (netdev)) +if (ixgbe_netif_running (netdev))ixgbe_reinit_locked (adapter); -else +else if (netif_device_present (netdev))ixgbe_reset (adapter); } }
@@ -1268,7 +1271,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev,while (test_and_set_bit (__IXGBE_RESETTING, &adapter->state))usleep_range (1000 ,2000 ); -if (!netif_running (adapter->netdev)) { +if (!ixgbe_netif_running (adapter->netdev)) {for (i =0 ; i < adapter->num_tx_queues; i++) adapter->tx_ring[i]->count = new_tx_count;for (i =0 ; i < adapter->num_xdp_queues; i++)
@@ -2251,10 +2254,11 @@ static void ixgbe_diag_test(struct net_device *netdev, struct ethtool_test *eth_test, u64 *data) { struct ixgbe_adapter *adapter = ixgbe_from_netdev(netdev); -bool if_running =netif_running (netdev); +bool if_running =ixgbe_netif_running (netdev); -if (ixgbe_removed (adapter->hw.hw_addr)) { -e_err (hw,"Adapter removed - test blocked\n" ); +if (ixgbe_removed (adapter->hw.hw_addr) || + !netif_device_present (netdev)) { +e_err (hw,"Adapter removed or detached - test blocked\n" ); data[0 ] =1 ; data[1 ] =1 ; data[2 ] =1 ;
@@ -2468,7 +2472,7 @@ static int ixgbe_nway_reset(struct net_device *netdev) {struct ixgbe_adapter *adapter =ixgbe_from_netdev (netdev); -if (netif_running (netdev)) +if (ixgbe_netif_running (netdev))ixgbe_reinit_locked (adapter);return 0 ;
@@ -2652,7 +2656,8 @@ static int ixgbe_set_coalesce(struct net_device *netdev,else /* rx only or mixed */ q_vector->itr = rx_itr_param; -ixgbe_write_eitr (q_vector); +if (netif_device_present (netdev)) +ixgbe_write_eitr (q_vector); }/*
@@ -3696,6 +3701,9 @@ static int ixgbe_set_eee_e610(struct net_device *netdev, kedata->eee_enabled)return -EOPNOTSUPP ; +if (!netif_device_present (netdev)) +return -ENETDOWN ; + hw->phy.eee_speeds_advertised = kedata->eee_enabled ? hw->phy.eee_speeds_supported :0 ;
@@ -3711,9 +3719,9 @@ static int ixgbe_set_eee_e610(struct net_device *netdev,else adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED ; -if (netif_running (netdev)) +if (ixgbe_netif_running (netdev))ixgbe_reinit_locked (adapter); -else +else if (netif_device_present (netdev))ixgbe_reset (adapter);return 0 ;
@@ -3795,9 +3803,9 @@ static int ixgbe_set_eee(struct net_device *netdev, struct ethtool_keee *edata) }/* reset link */ -if (netif_running (netdev)) +if (ixgbe_netif_running (netdev))ixgbe_reinit_locked (adapter); -else +else if (netif_device_present (netdev))ixgbe_reset (adapter);return 0 ;
@@ -3879,7 +3887,7 @@ static int ixgbe_set_priv_flags(struct net_device *netdev, u32 priv_flags) adapter->flags2 = flags2;/* reset interface to repopulate queues */ -if (netif_running (netdev)) +if (ixgbe_netif_running (netdev))ixgbe_reinit_locked (adapter); }
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +22 -7
@@ -830,27 +830,34 @@ static void ixgbe_fcoe_ddp_disable(struct ixgbe_adapter *adapter)* * Turns on FCoE offload feature in 82599. * -* Returns : 0 indicates success or -EINVAL on failure +* Returns: 0 on success or a negative error code on failure */ int ixgbe_fcoe_enable (struct net_device *netdev) {struct ixgbe_adapter *adapter =ixgbe_from_netdev (netdev);struct ixgbe_fcoe *fcoe = &adapter->fcoe; +bool running; +/* libfcoe calls ndo_fcoe_disable() even when this callback fails. */ atomic_inc (&fcoe->refcnt); +if (!netif_device_present (netdev)) +return -ENETDOWN ; +if (!(adapter->flags &IXGBE_FLAG_FCOE_CAPABLE ))return -EINVAL ;if (adapter->flags &IXGBE_FLAG_FCOE_ENABLED )return -EINVAL ; + running =netif_running (netdev); +e_info (drv,"Enabling FCoE offload features.\n" );if (adapter->flags &IXGBE_FLAG_SRIOV_ENABLED )e_warn (probe,"Enabling FCoE on PF will disable legacy VFs\n" ); -if (netif_running (netdev)) +if (running) netdev->netdev_ops->ndo_stop (netdev);/* Allocate per CPU memory to track DDP pools */
@@ -864,8 +871,9 @@ int ixgbe_fcoe_enable(struct net_device *netdev)/* release existing queues and reallocate them */ ixgbe_clear_interrupt_scheme (adapter);ixgbe_init_interrupt_scheme (adapter); + adapter->fcoe.reinit_pending = false; -if (netif_running (netdev)) +if (running) netdev->netdev_ops->ndo_open (netdev);return 0 ;
@@ -882,6 +890,7 @@ int ixgbe_fcoe_enable(struct net_device *netdev)int ixgbe_fcoe_disable (struct net_device *netdev) {struct ixgbe_adapter *adapter =ixgbe_from_netdev (netdev); +bool running;if (!atomic_dec_and_test (&adapter->fcoe.refcnt))return -EINVAL ;
@@ -889,8 +898,10 @@ int ixgbe_fcoe_disable(struct net_device *netdev)if (!(adapter->flags &IXGBE_FLAG_FCOE_ENABLED ))return -EINVAL ; + running =ixgbe_netif_running (netdev); +e_info (drv,"Disabling FCoE offload features.\n" ); -if (netif_running (netdev)) +if (running) netdev->netdev_ops->ndo_stop (netdev);/* Free per CPU memory to track DDP pools */
@@ -903,10 +914,14 @@ int ixgbe_fcoe_disable(struct net_device *netdev)netdev_features_change (netdev);/* release existing queues and reallocate them */ -ixgbe_clear_interrupt_scheme (adapter); -ixgbe_init_interrupt_scheme (adapter); +if (netif_device_present (netdev)) { +ixgbe_clear_interrupt_scheme (adapter); +ixgbe_init_interrupt_scheme (adapter); + }else { + adapter->fcoe.reinit_pending = true; + } -if (netif_running (netdev)) +if (running) netdev->netdev_ops->ndo_open (netdev);return 0 ;
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.h +1 -0
@@ -58,6 +58,7 @@ struct ixgbe_fcoe {dma_addr_t extra_ddp_buffer_dma;unsigned long mode;u8 up; + bool reinit_pending; };#endif /* _IXGBE_FCOE_H */
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +39 -3
78 lines not on this page · raw message
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +2 -2
@@ -39,7 +39,7 @@ static int ixgbe_xsk_pool_enable(struct ixgbe_adapter *adapter,if (err)return err; - if_running =netif_running (adapter->netdev) && + if_running =ixgbe_netif_running (adapter->netdev) &&ixgbe_enabled_xdp_adapter (adapter);if (if_running)
@@ -71,7 +71,7 @@ static int ixgbe_xsk_pool_disable(struct ixgbe_adapter *adapter, u16 qid)if (!pool)return -EINVAL ; - if_running =netif_running (adapter->netdev) && + if_running =ixgbe_netif_running (adapter->netdev) &&ixgbe_enabled_xdp_adapter (adapter);if (if_running)
Signature · 1 line
2.53.0
Simon Horman
reviewerRe: [PATCH iwl-net v2 1/4] ixgbe: Refactor device operations to check whether netdev is available
Quoted 7 lines · Sergey Temerkhanov
Refactor several ixgbe driver operations to check whether the netdev they operate on is enabled. This will allow the system to get synchronized, for example, during the PCI resets.
Fixes f7f37e7ff2b9 ("ixgbe: handle close/suspend race with netif_device_detach/present")Signed-off-by Sergey Temerkhanov <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>
I think the foce changes in this patch should be called out in the patch description. Or, if feasible, moved to a separate patch.
...
PATCH v2 2/4 ixgbe: Fix FCoE refcount taking for unsupported adapters
In reply to Sergey Temerkhanovixgbe_fcoe_enable() increments the FCoE reference count before checking whether the device supports FCoE. The unsupported adapters shall not take a reference while the ones which have FCoE already enabled only need to skip hardware initialization.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +12 -3
@@ -838,15 +838,21 @@ int ixgbe_fcoe_enable(struct net_device *netdev)struct ixgbe_fcoe *fcoe = &adapter->fcoe;bool running; +/* Unsupported adapters do not take a reference */ +if (!(adapter->flags &IXGBE_FLAG_FCOE_CAPABLE )) +return -EINVAL ; +/* libfcoe calls ndo_fcoe_disable() even when this callback fails. */ atomic_inc (&fcoe->refcnt);if (!netif_device_present (netdev))return -ENETDOWN ; -if (!(adapter->flags &IXGBE_FLAG_FCOE_CAPABLE )) -return -EINVAL ; - +/* If offload is enabled, only skip HW init, but keep the reference. +* ixgbe_fcoe_disable() decreases the refcount for this case and only +* disables the offload when the refcount reaches 0. This handles the case +* where multiple offload interfaces are enabled on the same PF (e.g. VLANs) +*/ if (adapter->flags &IXGBE_FLAG_FCOE_ENABLED )return -EINVAL ;
@@ -892,6 +898,9 @@ int ixgbe_fcoe_disable(struct net_device *netdev)struct ixgbe_adapter *adapter =ixgbe_from_netdev (netdev);bool running; +if (!(adapter->flags &IXGBE_FLAG_FCOE_CAPABLE )) +return -EINVAL ; +if (!atomic_dec_and_test (&adapter->fcoe.refcnt))return -EINVAL ;
Signature · 1 line
2.53.0
Re: [PATCH iwl-net v2 2/4] ixgbe: Fix FCoE refcount taking for unsupported adapters
Quoted 7 lines · Sergey Temerkhanov
ixgbe_fcoe_enable()increments the FCoE reference count before checking whether the device supports FCoE. The unsupported adapters shall not take a reference while the ones which have FCoE already enabled only need to skip hardware initialization.Fixes 27ab76065c0c ("ixgbe: add a refcnt when turning on/off FCoE offload capability")Signed-off-by Sergey Temerkhanov <[email protected]>
PATCH v2 3/4 ixgbe: Restore previous XDP program on ixgbe_setup_tc() failure
In reply to Sergey TemerkhanovWhen enabling or disabling an XDP program requires a queue reconfiguration, ixgbe_xdp_setup() swaps in the new program with xchg() before calling ixgbe_setup_tc(). If ixgbe_setup_tc() fails, the adapter was left pointing at the new program even though the reconfiguration did not complete, leaking the reference to the old program and leaving inconsistent state.
ixgbe_setup_tc() may have already reconfigured the queues for the new program before failing. The XDP ring layout then no longer matches the previous program, for example when removing a program has removed the XDP TX rings. Restore the previous program and rebuild the queues for it so adapter->xdp_prog remains consistent with the ring configuration. Otherwise, a later open could run XDP without XDP TX rings and dereference a NULL ring. ixgbe_setup_tc() handles the device having been left down by the failed reconfiguration.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +38 -2
@@ -7348,6 +7348,25 @@ static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)ixgbe_free_rx_resources (adapter->rx_ring[i]); } +static bool ixgbe_ring_resources_allocated (struct ixgbe_adapter *adapter) +{ +int i; + +for (i =0 ; i < adapter->num_tx_queues; i++) +if (adapter->tx_ring[i] && adapter->tx_ring[i]->desc) +return true; + +for (i =0 ; i < adapter->num_xdp_queues; i++) +if (adapter->xdp_ring[i] && adapter->xdp_ring[i]->desc) +return true; + +for (i =0 ; i < adapter->num_rx_queues; i++) +if (adapter->rx_ring[i] && adapter->rx_ring[i]->desc) +return true; + +return false; +} +/** * ixgbe_max_xdp_frame_size - returns the maximum allowed frame size for XDP * @adapter: device handle, pointer to adapter
@@ -9921,6 +9940,7 @@ int ixgbe_setup_tc(struct net_device *dev, u8 tc) {struct ixgbe_adapter *adapter =ixgbe_from_netdev (dev);struct ixgbe_hw *hw = &adapter->hw; +bool running;/* Hardware supports up to 8 traffic classes */ if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
@@ -9933,7 +9953,17 @@ int ixgbe_setup_tc(struct net_device *dev, u8 tc)* match packet buffer alignment. Unfortunately, the * hardware is not flexible enough to do this dynamically. */ -if (netif_running (dev)) +if (!netif_device_present (dev)) +return -ENETDOWN ; + + running =netif_running (dev); + +/* If a previous ixgbe_open() failed, the netdev can still be +* administratively up after IRQs and ring resources have already been +* released. Skip ixgbe_close() only in that state; ixgbe_down() leaves +* resources for ixgbe_close() to release. +*/ +if (running &&ixgbe_ring_resources_allocated (adapter))ixgbe_close (dev);else ixgbe_reset (adapter);
@@ -10972,8 +11002,14 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)synchronize_rcu (); err =ixgbe_setup_tc (dev, adapter->hw_tcs); -if (err) +if (err) { +xchg (&adapter->xdp_prog, old_prog); + err =ixgbe_setup_tc (dev, adapter->hw_tcs); +/* An ndo_bpf error leaves old_prog attached in the core. */ +if (err) +return err;return -EINVAL ; + }if (!prog)xdp_features_clear_redirect_target (dev); }else {
Signature · 1 line
2.53.0
Re: [PATCH iwl-net v2 3/4] ixgbe: Restore previous XDP program on ixgbe_setup_tc() failure
Quoted 16 lines · Sergey Temerkhanov
When enabling or disabling an XDP program requires a queue reconfiguration,
ixgbe_xdp_setup()swaps in the new program withxchg()before callingixgbe_setup_tc(). Ifixgbe_setup_tc()fails, the adapter was left pointing at the new program even though the reconfiguration did not complete, leaking the reference to the old program and leaving inconsistent state.
ixgbe_setup_tc()may have already reconfigured the queues for the new program before failing. The XDP ring layout then no longer matches the previous program, for example when removing a program has removed the XDP TX rings. Restore the previous program and rebuild the queues for it soadapter->xdp_progremains consistent with the ring configuration. Otherwise, a later open could run XDP without XDP TX rings and dereference a NULL ring.ixgbe_setup_tc()handles the device having been left down by the failed reconfiguration.
Quoted 3 lines
Fixes 3fe1d0a48d21 ("ixgbe: XDP: fix checker warning from rcu pointer")Signed-off-by Sergey Temerkhanov <[email protected]>Reviewed-by Przemyslaw Korba <[email protected]>
PATCH v2 4/4 ixgbe: Implement PCI reset handler
In reply to Sergey TemerkhanovImplement PCI device reset handler to allow the network device to get re-initialized and function after a PCI-level reset.
This is necessary for the adapter to avoid TX queue timeouts occurring after the PCI reset is performed via sysfs during its operation.
The reset codepath may trigger a number of dependencies in the reset of the driver, so that it is necessary to check if the netdev is present and running there.
--- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 1 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 111 ++++++++++++++++++ 2 files changed, 112 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +1 -0
@@ -912,6 +912,7 @@ enum ixgbe_state_t { __IXGBE_PTP_TX_IN_PROGRESS, __IXGBE_RESET_REQUESTED, __IXGBE_PHY_INIT_COMPLETE, + __IXGBE_PCI_RESET_PREPARED, }; struct ixgbe_cb {
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +111 -0
141 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH iwl-net v2 4/4] ixgbe: Implement PCI reset handler
Quoted 7 lines · Sergey Temerkhanov
Implement PCI device reset handler to allow the network device to get re-initialized and function after a PCI-level reset.
This is necessary for the adapter to avoid TX queue timeouts occurring after the PCI reset is performed via sysfs during its operation.
Quoted 8 lines
The reset codepath may trigger a number of dependencies in the reset of the driver, so that it is necessary to check if the netdev is present and running there.
Fixes 711d57796f5c ("PCI: expose function reset capability in sysfs")Signed-off-by Sergey Temerkhanov <[email protected]>Reviewed-by Przemyslaw Korba <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>