Netdev List
 help / color / mirror / Atom feed
From: Aaron Ma <aaron.ma@canonical.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org
Cc: Henry Tieman <henry.w.tieman@intel.com>,
	intel-wired-lan@lists.osuosl.org
Subject: [PATCH net v3 1/2] ice: restore DDP state during PFR recovery
Date: Thu,  3 Dec 2026 11:53:19 +0800	[thread overview]
Message-ID: <20261203035320.187412-1-aaron.ma@canonical.com> (raw)

During system suspend and resume, affected adapters lose firmware DDP,
DVM, and UDP tunnel state, while PFR recovery only rebuilds software
tables and runs concurrently across PFs of the same adapter:

  ice 0000:04:00.0: Update pkg failed: err -5
  ice 0000:04:00.0: package load failed, -12
  ice 0000:04:00.0: Rebuild failed, unload and reload driver

This was reproduced during suspend/resume testing on Intel E810-XXV-2
(8086:159b) and E835-CC (8086:124a) adapters.

Serialize PF configuration clearing, package reload, and PFR UDP tunnel
replay per adapter in ice_rebuild(). On PFR, reload the cached package
without rescanning hints, restore DVM mode and default recipes, and
reprogram offloaded UDP tunnel ports under rtnl_lock(). Release the
adapter reference after stopping the service task in probe error unwind
and driver removal, found by code inspection.

Fixes: 462acf6aca85 ("ice: Enable DDP package download")
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
v2 -> v3:
- Scope rebuild_lock around ice_clear_pf_cfg(), DDP reload, and PFR UDP
  tunnel replay inside ice_rebuild(), clearing PF config first.
- Defer ice_adapter_put() until after ice_deinit_dev() in ice_probe() and
  ice_remove() instead of stopping the service task early.
- Preserve cached package hints on reload, clear cached tunnel ports under
  hw->tnl_lock, and replay UDP tunnel ports via udp_tunnel_nic_reset_ntf()
  under rtnl_lock().
- Restore DVM port parameters and default recipes when needed, skipping
  firmware writes for matching recipes, and avoid Safe Mode log on PFR
  failure.
- Drop Przemek's Reviewed-by due to substantial changes.

v1 -> v2:
- Stop service task early in ice_remove() to prevent use-after-free on
  pf->adapter if rebuild is in flight.

 drivers/net/ethernet/intel/ice/ice_adapter.c  |  2 +
 drivers/net/ethernet/intel/ice/ice_adapter.h  |  4 +
 drivers/net/ethernet/intel/ice/ice_ddp.c      | 10 ++-
 drivers/net/ethernet/intel/ice/ice_main.c     | 78 +++++++++++++++----
 drivers/net/ethernet/intel/ice/ice_switch.c   | 15 +++-
 .../net/ethernet/intel/ice/ice_vlan_mode.c    |  2 +-
 .../net/ethernet/intel/ice/ice_vlan_mode.h    |  1 +
 7 files changed, 95 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.c b/drivers/net/ethernet/intel/ice/ice_adapter.c
index aa2d8addae5be..9a7565a54c0fe 100644
--- a/drivers/net/ethernet/intel/ice/ice_adapter.c
+++ b/drivers/net/ethernet/intel/ice/ice_adapter.c
@@ -73,6 +73,7 @@ static struct ice_adapter *ice_adapter_new(struct pci_dev *pdev)
 	for (int i = 0; i < ARRAY_SIZE(adapter->cpi_phy_lock); i++)
 		mutex_init(&adapter->cpi_phy_lock[i]);
 	mutex_init(&adapter->cgu_synce_lock);
+	mutex_init(&adapter->rebuild_lock);
 	refcount_set(&adapter->refcount, 1);
 
 	spin_lock_init(&adapter->ports.lock);
@@ -87,6 +88,7 @@ static void ice_adapter_free(struct ice_adapter *adapter)
 	for (int i = 0; i < ARRAY_SIZE(adapter->cpi_phy_lock); i++)
 		mutex_destroy(&adapter->cpi_phy_lock[i]);
 	mutex_destroy(&adapter->cgu_synce_lock);
+	mutex_destroy(&adapter->rebuild_lock);
 
 	cleanup_srcu_struct(&adapter->ports.srcu);
 
diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.h b/drivers/net/ethernet/intel/ice/ice_adapter.h
index fd5585005d91b..18120432e1fd9 100644
--- a/drivers/net/ethernet/intel/ice/ice_adapter.h
+++ b/drivers/net/ethernet/intel/ice/ice_adapter.h
@@ -43,6 +43,8 @@ struct ice_port_list {
  *               Index 0 = PHY0, index 1 = PHY1. Used on E825C devices.
  * @cgu_synce_lock: Mutex serializing changes of the CGU registers R10 and R11,
  *                  which all PFs reach. Used on E825C devices.
+ * @rebuild_lock: Mutex serializing package and recipe rebuilds across PFs of
+ *                the same adapter
  * @ctrl_pf: Control PF of the adapter
  * @ports: Ports list
  * @index: 64-bit index cached for collision detection on 32bit systems
@@ -57,6 +59,8 @@ struct ice_adapter {
 	struct mutex cpi_phy_lock[ICE_E825_MAX_PHYS];
 	/* Serialize changes of the SyncE CGU registers (E825C only) */
 	struct mutex cgu_synce_lock;
+	/* Serialize package and recipe rebuilds across PFs */
+	struct mutex rebuild_lock;
 
 	struct ice_pf *ctrl_pf;
 	struct ice_port_list ports;
diff --git a/drivers/net/ethernet/intel/ice/ice_ddp.c b/drivers/net/ethernet/intel/ice/ice_ddp.c
index d50c555851fbd..bedb9362d4098 100644
--- a/drivers/net/ethernet/intel/ice/ice_ddp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ddp.c
@@ -2204,6 +2204,7 @@ enum ice_ddp_state ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
 	enum ice_ddp_state state;
 	struct ice_pkg_hdr *pkg;
 	struct ice_seg *seg;
+	u16 i;
 
 	if (!buf || !len)
 		return ICE_DDP_PKG_ERR;
@@ -2234,7 +2235,14 @@ enum ice_ddp_state ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
 		return state;
 
 	/* initialize package hints and then download package */
-	ice_init_pkg_hints(hw, seg);
+	if (hw->seg != seg) {
+		ice_init_pkg_hints(hw, seg);
+	} else {
+		mutex_lock(&hw->tnl_lock);
+		for (i = 0; i < hw->tnl.count; i++)
+			hw->tnl.tbl[i].port = 0;
+		mutex_unlock(&hw->tnl_lock);
+	}
 	state = ice_download_pkg(hw, pkg, seg);
 	if (state == ICE_DDP_PKG_ALREADY_LOADED) {
 		ice_debug(hw, ICE_DBG_INIT,
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 47c6798c97e8f..a664fbde49d17 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -4294,6 +4294,49 @@ ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
 	set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
 }
 
+static int ice_reload_pkg_pfr(struct ice_pf *pf)
+{
+	struct device *dev = ice_pf_to_dev(pf);
+	struct ice_hw *hw = &pf->hw;
+	enum ice_ddp_state state;
+	bool dvm;
+	int err;
+
+	dvm = ice_is_dvm_ena(hw);
+	state = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
+	if (!ice_is_init_pkg_successful(state)) {
+		dev_err(dev, "failed to reload DDP package during PFR: %d\n",
+			state);
+		return -EIO;
+	}
+	ice_log_pkg_init(hw, state);
+
+	if (state != ICE_DDP_PKG_SUCCESS && dvm && !ice_is_dvm_ena(hw)) {
+		err = ice_aq_set_port_params(hw->port_info, true, NULL);
+		if (!err)
+			ice_post_pkg_dwnld_vlan_mode_cfg(hw);
+	}
+
+	if (dvm && !ice_is_dvm_ena(hw)) {
+		dev_err(dev, "failed to restore DVM mode during PFR\n");
+		return -EIO;
+	}
+
+	/* PFR can lose DVM recipes after system suspend when the
+	 * package itself remained loaded in firmware.
+	 */
+	if (state != ICE_DDP_PKG_SUCCESS && ice_is_dvm_ena(hw)) {
+		err = ice_dvm_update_dflt_recipes(hw);
+		if (err) {
+			dev_err(dev, "failed to restore default DVM recipes: %d\n",
+				err);
+			return err;
+		}
+	}
+
+	return 0;
+}
+
 /**
  * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
  * @pf: pointer to the PF structure
@@ -5290,11 +5333,13 @@ ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
 unroll_dev_init:
 	need_dev_deinit = true;
 unroll_adapter:
-	ice_adapter_put(pdev);
-unroll_hw_init:
 	ice_deinit_hw(hw);
 	if (need_dev_deinit)
 		ice_deinit_dev(pf);
+	ice_adapter_put(pdev);
+	return err;
+unroll_hw_init:
+	ice_deinit_hw(hw);
 	return err;
 }
 
@@ -5403,10 +5448,10 @@ static void ice_remove(struct pci_dev *pdev)
 	ice_setup_mc_magic_wake(pf);
 	ice_set_wake(pf);
 
-	ice_adapter_put(pdev);
 	ice_deinit_hw(&pf->hw);
 
 	ice_deinit_dev(pf);
+	ice_adapter_put(pdev);
 	ice_aq_cancel_waiting_tasks(pf);
 	set_bit(ICE_DOWN, pf->state);
 }
@@ -7682,21 +7727,28 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
 		goto err_init_ctrlq;
 	}
 
+	mutex_lock(&pf->adapter->rebuild_lock);
+	err = ice_clear_pf_cfg(hw);
+	if (err)
+		dev_err(dev, "clear PF configuration failed %d\n", err);
+
 	/* if DDP was previously loaded successfully */
-	if (!ice_is_safe_mode(pf)) {
-		/* reload the SW DB of filter tables */
-		if (reset_type == ICE_RESET_PFR)
-			ice_fill_blk_tbls(hw);
-		else
+	if (!err && !ice_is_safe_mode(pf)) {
+		if (reset_type == ICE_RESET_PFR) {
+			err = ice_reload_pkg_pfr(pf);
+			if (!err && vsi && vsi->netdev) {
+				rtnl_lock();
+				udp_tunnel_nic_reset_ntf(vsi->netdev);
+				rtnl_unlock();
+			}
+		} else {
 			/* Reload DDP Package after CORER/GLOBR reset */
 			ice_load_pkg(NULL, pf);
+		}
 	}
-
-	err = ice_clear_pf_cfg(hw);
-	if (err) {
-		dev_err(dev, "clear PF configuration failed %d\n", err);
+	mutex_unlock(&pf->adapter->rebuild_lock);
+	if (err)
 		goto err_init_ctrlq;
-	}
 
 	ice_clear_pxe_mode(hw);
 
diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
index d873eda9af826..e6541cb8ea796 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.c
+++ b/drivers/net/ethernet/intel/ice/ice_switch.c
@@ -2066,6 +2066,7 @@ ice_update_recipe_lkup_idx(struct ice_hw *hw,
 {
 	struct ice_aqc_recipe_data_elem *rcp_list;
 	u16 num_recps = ICE_MAX_NUM_RECIPES;
+	u8 lkup_val;
 	int status;
 
 	rcp_list = kzalloc_objs(*rcp_list, num_recps);
@@ -2078,9 +2079,19 @@ ice_update_recipe_lkup_idx(struct ice_hw *hw,
 	if (status) {
 		ice_debug(hw, ICE_DBG_SW, "Failed to get recipe %d, status %d\n",
 			  params->rid, status);
-		goto error_out;
+		goto out;
 	}
 
+	lkup_val = params->fv_idx;
+	if (params->ignore_valid)
+		lkup_val |= ICE_AQ_RECIPE_LKUP_IGNORE;
+
+	if (rcp_list->content.lkup_indx[params->lkup_idx] == lkup_val &&
+	    (!params->mask_valid ||
+	     rcp_list->content.mask[params->lkup_idx] ==
+	     cpu_to_le16(params->mask)))
+		goto out;
+
 	/* only modify existing recipe's lkup_idx and mask if valid, while
 	 * leaving all other fields the same, then update the recipe firmware
 	 */
@@ -2100,7 +2111,7 @@ ice_update_recipe_lkup_idx(struct ice_hw *hw,
 			  params->mask, params->mask_valid ? "true" : "false",
 			  status);
 
-error_out:
+out:
 	kfree(rcp_list);
 	return status;
 }
diff --git a/drivers/net/ethernet/intel/ice/ice_vlan_mode.c b/drivers/net/ethernet/intel/ice/ice_vlan_mode.c
index 92c6f83a7efec..69dce2997845c 100644
--- a/drivers/net/ethernet/intel/ice/ice_vlan_mode.c
+++ b/drivers/net/ethernet/intel/ice/ice_vlan_mode.c
@@ -240,7 +240,7 @@ static struct ice_update_recipe_lkup_idx_params ice_dvm_dflt_recipes[] = {
  * ice_dvm_update_dflt_recipes - update default switch recipes in DVM
  * @hw: hardware structure used to update the recipes
  */
-static int ice_dvm_update_dflt_recipes(struct ice_hw *hw)
+int ice_dvm_update_dflt_recipes(struct ice_hw *hw)
 {
 	unsigned long i;
 
diff --git a/drivers/net/ethernet/intel/ice/ice_vlan_mode.h b/drivers/net/ethernet/intel/ice/ice_vlan_mode.h
index a0fb743d08e20..5dc705435f56a 100644
--- a/drivers/net/ethernet/intel/ice/ice_vlan_mode.h
+++ b/drivers/net/ethernet/intel/ice/ice_vlan_mode.h
@@ -8,6 +8,7 @@ struct ice_hw;
 
 bool ice_is_dvm_ena(struct ice_hw *hw);
 int ice_set_vlan_mode(struct ice_hw *hw);
+int ice_dvm_update_dflt_recipes(struct ice_hw *hw);
 void ice_post_pkg_dwnld_vlan_mode_cfg(struct ice_hw *hw);
 
 #endif /* _ICE_VLAN_MODE_H */
-- 
2.55.0


             reply	other threads:[~2026-12-03  3:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  3:53 Aaron Ma [this message]
2026-12-03  3:53 ` [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup Aaron Ma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203035320.187412-1-aaron.ma@canonical.com \
    --to=aaron.ma@canonical.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=henry.w.tieman@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox