Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX
@ 2026-12-04 15:29 Satish Kharat
  2026-12-04 15:29 ` [PATCH net-next v6 1/7] net: add netif_rx_mode_schedule_update() Satish Kharat
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

An ENIC V2 VF relies on the PF for its station address and receive
filters. Add VF mailbox support for the station address, secondary address
lists, and packet-filter modes. Serialize VF requests around the single
expected reply slot. PF notifications and their acknowledgments keep
their existing separate path.

Patch 1 adds a netdev helper to restart the bounded receive-mode retry
sequence. Patch 2 establishes VF request ownership. Patches 3 and 4
recover the VF mailbox and validate replies. Patch 5 adds synchronized
publication of driver-selected addresses. Patches 6 and 7 manage the VF
station and administrative MAC policy and receive-filter replay.

The in-tree V2 PF enable path remains dormant. A later PF series must
supply the mailbox and cleanup contracts and register sriov_configure.
This series requires a compatible PF that permits CMD_SRIOV_STATS_GET
for the VF firmware index query. The net-next base contains both
prerequisite commits:

  b3ae89a2e167 ("enic: retain admin-channel DMA until queues stop")
  65230b3ffd75 ("enic: require DEVCMD2 and set the V2 VF mailbox source")

Changes in v6:
- Refresh the net-next base.
- Explain the VF request mutex and existing send-error cleanup.
- Arm RX quarantine for every V2 VF rebuild and invalidate old PF
  registration and link state when replacing the admin channel.
- Remove the unreachable open-time reset fallback and clarify VF and PF
  reset ordering.
- Narrow the capability-version warning to the unsupported-version case.
- Preserve provisioned probe MAC assignment metadata and leave
  perm_addr unset for a generated probe address. Align the temporary
  MAC addresses and exclude ordinary station delete during PCI
  removal.
- Serialize PF-driven MAC writes with sysfs and SIOCGIFHWADDR reads.
- Skip asynchronous receive-filter programming while the datapath is
  closed and replay after a successful internal reopen.

The secondary batches carry no station flag. Both inspected PF
implementations scope the skipped-delete precheck to station operations.
A skipped secondary delete still requires recovery because the removed
address might remain installed.

The cover for v5 was sent in error and withdrawn. v4 is the previous
reviewed posting. Sashiko reported the findings. Codex assisted with
triage, the v6 code changes and changelog, and testing. The focused test
was designed to check concurrent address reads during PF-driven updates.

Link to v4: https://lore.kernel.org/netdev/20261130-b4-enic-sriov-v2-vf-receive-control-v4-0-5858d5a9ecb1@cisco.com/
Link to the v5 withdrawal: https://lore.kernel.org/r/20261201010949.3475009-1-satishkh@cisco.com/

Hardware validation

- On a VIC 14xx adapter with a compatible PF, the v6 VF passed an
  SR-IOV functional run covering VF creation and VFIO passthrough to a
  KVM guest, fixed and delegated MAC policy, VF down/up, guest driver
  unload, and VF teardown. The initial permanent address was preserved
  across live PF reassignment.
- Bidirectional ICMP passed at standard and 1400-byte payload sizes.
  Firmware readback confirmed secondary unicast and multicast filter
  installation and removal.
- Concurrent sysfs and SIOCGIFHWADDR readers returned complete addresses
  throughout 64 live PF MAC changes.

Earlier full-stack runs covered VF recreation, module reload, ring
resizing, and bidirectional ICMP, TCP and UDP, including cross-DUT jumbo
traffic between VIC 14xx and VIC 15xxx adapters. Earlier instrumented
runs covered mailbox recovery, completion cleanup after a failed open,
and reopen after a QP_DISABLE error once both admin queues stopped.

---
Satish Kharat (7):
      net: add netif_rx_mode_schedule_update()
      enic: serialize V2 VF mailbox requests
      enic: recover V2 VF mailbox after request failure
      enic: validate V2 VF configuration replies
      net: add dev_addr_set_sync() for driver address updates
      enic: manage V2 VF station and administrative MAC
      enic: configure V2 VF receive mode over mailbox

 drivers/net/ethernet/cisco/enic/enic.h         |   65 +-
 drivers/net/ethernet/cisco/enic/enic_admin.c   |   39 +-
 drivers/net/ethernet/cisco/enic/enic_dev.c     |   11 +
 drivers/net/ethernet/cisco/enic/enic_dev.h     |    1 +
 drivers/net/ethernet/cisco/enic/enic_ethtool.c |    5 +
 drivers/net/ethernet/cisco/enic/enic_main.c    | 1743 ++++++++++++++++++++++--
 drivers/net/ethernet/cisco/enic/enic_mbox.c    |  753 +++++++++-
 drivers/net/ethernet/cisco/enic/enic_mbox.h    |   84 ++
 drivers/net/ethernet/cisco/enic/enic_rq.c      |   11 +-
 drivers/net/ethernet/cisco/enic/vnic_dev.c     |   21 +-
 drivers/net/ethernet/cisco/enic/vnic_dev.h     |    2 +
 include/linux/netdevice.h                      |    3 +
 net/core/dev_addr_lists.c                      |   21 +
 net/core/dev_api.c                             |   21 +
 14 files changed, 2632 insertions(+), 148 deletions(-)
---
base-commit: ed3135d0881a926de56a7f490dea3d51698ba118
change-id: 20260916-b4-enic-sriov-v2-vf-receive-control-b5c40bdae5b9

Best regards,
--  
Satish Kharat <satishkh@cisco.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH net-next v6 1/7] net: add netif_rx_mode_schedule_update()
  2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
@ 2026-12-04 15:29 ` Satish Kharat
  2026-12-04 15:29 ` [PATCH net-next v6 2/7] enic: serialize V2 VF mailbox requests Satish Kharat
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

Add a receive-mode scheduling helper for callers which start a new update
after a state transition. Cancel a pending retry and reset its backoff
before queueing the immediate update so the preceding operation's retry
state cannot shorten the new operation's bounded retry sequence.

The helper preserves address-list synchronization state. Callers which
need to replay configuration lost by the device must unsynchronize the
affected address lists before scheduling the update.

The first callers are added by the enic V2 VF patches later in this
series: the administrative-MAC notification, the V2 VF set-MAC path, and
the _enic_change_mtu(), soft-reset and hang-reset reopen paths.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 include/linux/netdevice.h |  1 +
 net/core/dev_addr_lists.c | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 694b6d29f680..b5427b953229 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -5233,6 +5233,7 @@ static inline void __dev_mc_unsync(struct net_device *dev,
 
 /* Functions used for secondary unicast and multicast support */
 void dev_set_rx_mode(struct net_device *dev);
+void netif_rx_mode_schedule_update(struct net_device *dev);
 void netif_rx_mode_schedule_retry(struct net_device *dev);
 int netif_set_promiscuity(struct net_device *dev, int inc);
 int dev_set_promiscuity(struct net_device *dev, int inc);
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index b6f25e487984..89ae77360a0b 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -1568,6 +1568,27 @@ static void netif_rx_mode_queue(struct net_device *dev)
 	__netdev_work_core_sched(dev, NETDEV_WORK_RX_MODE);
 }
 
+/**
+ * netif_rx_mode_schedule_update() - schedule a new receive-mode update
+ * @dev: network device
+ *
+ * Cancel any pending retry and reset its backoff before scheduling an
+ * immediate receive-mode update. This does not reset address-list
+ * synchronization state. Callers which need to replay lost device state must
+ * unsynchronize the affected address lists before scheduling the update.
+ *
+ * Context: sleepable. The caller must hold the device operations lock, or
+ * RTNL for a device which still uses RTNL-compatible operations.
+ */
+void netif_rx_mode_schedule_update(struct net_device *dev)
+{
+	might_sleep();
+	netdev_assert_locked_ops_compat(dev);
+	netif_rx_mode_cancel_retry(dev);
+	netif_rx_mode_queue(dev);
+}
+EXPORT_SYMBOL_GPL(netif_rx_mode_schedule_update);
+
 static void netif_rx_mode_retry(struct timer_list *t)
 {
 	struct net_device *dev =

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH net-next v6 2/7] enic: serialize V2 VF mailbox requests
  2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
  2026-12-04 15:29 ` [PATCH net-next v6 1/7] net: add netif_rx_mode_schedule_update() Satish Kharat
@ 2026-12-04 15:29 ` Satish Kharat
  2026-12-04 15:29 ` [PATCH net-next v6 3/7] enic: recover V2 VF mailbox after request failure Satish Kharat
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

The VF has one expected-reply slot and one completion. Prepare for the
additional VF configuration requests introduced later in this series
by serializing the request lifetime with a VF-only mutex.

Hold the mutex from before the reply slot is armed until the caller
consumes the reply, timeout or send error. Recheck registration after
taking the mutex. The sender already clears an armed reply on send
failure. Unsolicited PF notifications and acknowledgments retain their
separate paths.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h      |  8 ++---
 drivers/net/ethernet/cisco/enic/enic_mbox.c | 49 +++++++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index a4f9f58c1adf..2ea2d22373b6 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -338,12 +338,12 @@ struct enic {
 	/* MBOX protocol state — mbox_lock serializes admin WQ sends */
 	struct mutex mbox_lock;
 	u64 mbox_msg_num;
-	/* MBOX request-reply state.  Existing request callers allow only one
-	 * request in flight.  The state lock arbitrates reply acceptance against
-	 * timeout invalidation, while mbox_comp publishes the accepted result to
-	 * the requester.
+	/* The VF request mutex serializes ownership of the reply slot.
+	 * The state lock arbitrates reply acceptance against timeout, and
+	 * mbox_comp publishes the accepted result to the requester.
 	 */
 	struct completion mbox_comp;
+	struct mutex vf_mbox_request_lock; /* serializes VF request lifetimes */
 	spinlock_t mbox_state_lock;	/* protects expected reply state */
 	u64 mbox_expected_msg_num;
 	u8 mbox_expected_reply;
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
index a1f8138d0bbd..d1b6f13c8002 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c
@@ -226,6 +226,32 @@ static int enic_mbox_wait_reply(struct enic *enic, unsigned long timeout_ms)
 	return err;
 }
 
+static void enic_mbox_vf_request_start(struct enic *enic)
+{
+	mutex_lock(&enic->vf_mbox_request_lock);
+	reinit_completion(&enic->mbox_comp);
+	spin_lock_bh(&enic->mbox_state_lock);
+	enic->mbox_expected_msg_num = 0;
+	enic->mbox_expected_reply = 0;
+	spin_unlock_bh(&enic->mbox_state_lock);
+}
+
+static void enic_mbox_vf_request_abort(struct enic *enic)
+{
+	lockdep_assert_held(&enic->vf_mbox_request_lock);
+	spin_lock_bh(&enic->mbox_state_lock);
+	enic->mbox_expected_reply = 0;
+	enic->mbox_expected_msg_num = 0;
+	spin_unlock_bh(&enic->mbox_state_lock);
+	mutex_unlock(&enic->vf_mbox_request_lock);
+}
+
+static void enic_mbox_vf_request_finish(struct enic *enic)
+{
+	lockdep_assert_held(&enic->vf_mbox_request_lock);
+	mutex_unlock(&enic->vf_mbox_request_lock);
+}
+
 int enic_mbox_send_link_state(struct enic *enic, u16 vf_id, u32 link_state)
 {
 	struct enic_mbox_pf_link_state_notif_msg notif = {};
@@ -631,6 +657,7 @@ int enic_mbox_vf_capability_check(struct enic *enic)
 	u32 version;
 	int err;
 
+	enic_mbox_vf_request_start(enic);
 	WRITE_ONCE(enic->pf_cap_version, 0);
 	req.version = cpu_to_le32(ENIC_MBOX_CAP_VERSION_1);
 
@@ -638,11 +665,14 @@ int enic_mbox_vf_capability_check(struct enic *enic)
 					ENIC_MBOX_VF_CAPABILITY_REQUEST,
 					ENIC_MBOX_VF_CAPABILITY_REPLY,
 					&req, sizeof(req));
-	if (err)
+	if (err) {
+		enic_mbox_vf_request_abort(enic);
 		return err;
+	}
 
 	err = enic_mbox_wait_reply(enic, 3000);
 	version = READ_ONCE(enic->pf_cap_version);
+	enic_mbox_vf_request_finish(enic);
 	if (err) {
 		netdev_warn(enic->netdev,
 			    "MBOX: no capability reply from PF\n");
@@ -664,15 +694,19 @@ int enic_mbox_vf_register(struct enic *enic)
 	bool registered;
 	int err;
 
+	enic_mbox_vf_request_start(enic);
 	WRITE_ONCE(enic->vf_registered, false);
 
 	err = enic_mbox_vf_send_request(enic, ENIC_MBOX_VF_REGISTER_REQUEST,
 					ENIC_MBOX_VF_REGISTER_REPLY, NULL, 0);
-	if (err)
+	if (err) {
+		enic_mbox_vf_request_abort(enic);
 		return err;
+	}
 
 	err = enic_mbox_wait_reply(enic, 3000);
 	registered = READ_ONCE(enic->vf_registered);
+	enic_mbox_vf_request_finish(enic);
 	if (err) {
 		netdev_warn(enic->netdev,
 			    "MBOX: VF registration with PF timed out\n");
@@ -692,16 +726,24 @@ int enic_mbox_vf_unregister(struct enic *enic)
 
 	if (!READ_ONCE(enic->vf_registered))
 		return 0;
+	enic_mbox_vf_request_start(enic);
+	if (!READ_ONCE(enic->vf_registered)) {
+		enic_mbox_vf_request_finish(enic);
+		return 0;
+	}
 
 	err = enic_mbox_vf_send_request(enic,
 					ENIC_MBOX_VF_UNREGISTER_REQUEST,
 					ENIC_MBOX_VF_UNREGISTER_REPLY,
 					NULL, 0);
-	if (err)
+	if (err) {
+		enic_mbox_vf_request_abort(enic);
 		return err;
+	}
 
 	err = enic_mbox_wait_reply(enic, 3000);
 	registered = READ_ONCE(enic->vf_registered);
+	enic_mbox_vf_request_finish(enic);
 	if (err)
 		return err;
 	if (registered)
@@ -719,6 +761,7 @@ void enic_mbox_init(struct enic *enic)
 	 */
 	if (!reinit) {
 		mutex_init(&enic->mbox_lock);
+		mutex_init(&enic->vf_mbox_request_lock);
 		init_completion(&enic->mbox_comp);
 		spin_lock_init(&enic->mbox_state_lock);
 		enic->mbox_msg_num = 0;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH net-next v6 3/7] enic: recover V2 VF mailbox after request failure
  2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
  2026-12-04 15:29 ` [PATCH net-next v6 1/7] net: add netif_rx_mode_schedule_update() Satish Kharat
  2026-12-04 15:29 ` [PATCH net-next v6 2/7] enic: serialize V2 VF mailbox requests Satish Kharat
@ 2026-12-04 15:29 ` Satish Kharat
  2026-12-05 16:28   ` netdev-bot+sashiko
  2026-12-04 15:29 ` [PATCH net-next v6 4/7] enic: validate V2 VF configuration replies Satish Kharat
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

A mailbox send can complete and still lose its reply. The VF then cannot
know whether the PF changed its state. A send-completion timeout is
different because the admin-WQ descriptor may still belong to the device.

Reconnect after a lost or inconsistent reply. For a posted-send timeout,
retain the mapping on the admin WQ, block sends, and start recovery after
releasing the sender lock. The prerequisite admin fix releases that graph
only when both admin queues stop; a retained graph cannot be reset or
reopened, and a final remove-time recheck may reclaim it.

Run V2 VF mailbox recovery on its own work item while sharing the
hang-reset sequence with the Tx watchdog. Claim queued mailbox recovery
only while reconnect or poisoned-send state remains pending. Ordinary open
may already have consumed the fault while holding RTNL. Keep genuine
watchdog work separate so coalesced mailbox and Tx events cannot lose
their scheduling reasons.

The VF recovery path requires the hang-reset pair, so issue CMD_HANG_RESET
directly rather than through the generic capability probe. Keep generic
capability selection for other ENIC functions. Serialize reset start/status
commands under devcmd_lock on every path. Issue runtime INIT after soft
reset completes for non-dynamic functions; dynamic vNICs follow their
probe-time initialization contract. A reset or INIT failure detaches the
netdev until the driver is rebound. Skip HANG_NOTIFY for mailbox recovery
because it reports an actual Tx hang. Queue-error recovery can still
use CMD_SOFT_RESET on a V2 VF. That path requires a PF which permits the
command and its status/INIT sequence, and it detaches the VF if soft reset
fails.

Close admin and stop the datapath before reset. Check stop, reset, INIT,
registration and reopen results before proceeding. Close an admin channel
opened for a VF when its datapath reopen fails. After successful recovery,
queue a follow-up only while reconnect or poisoned-send state remains
pending. Fresh registration consumes faults from the prior channel; a
failed handshake leaves carrier off and RX gated. Avoid a reset loop
when a PF cannot complete registration. A later administrative
down/up may retry when the device and queue ownership allow it.

A QP_DISABLE error can be returned after both admin queues stop and the
old graph is released. During VF reconnect, use the resulting DOWN state
to permit reopen; keep a quarantined graph blocked.

Track committed software open/stop pairing with datapath_open. IFF_UP can
remain set after failed internal recovery, so later close must not disable
NAPI twice or program a live station filter on an actually closed VF. Free
existing IRQ callbacks before fallible queue-stop polling; on failure
detach the netdev and refuse open, reset and ring reconfiguration. This
bookkeeping does not prove DMA ownership or add generic queue or page-pool
quarantine. The generic queue-disable error path remains separate work.

A V2 VF can receive packets after CMD_ENABLE succeeds but before the final
mailbox-state check completes. Without late-unwind cleanup, a failed check
leaves completed entries in data CQs which a later open reuses. On this
late failure only, mask and synchronize datapath IRQs. After the existing
disable passes report every generic WQ and RQ stopped, clean TX buffers,
data CQs and interrupt credits. Do not perform that extra cleanup when any
queue fails to stop; this change does not establish ownership of DMA
memory for a stuck generic queue or its RX page pool.

A test-only mailbox fault after a real CMD_ENABLE left 4,080 RQ
completions under directed VF traffic. The late unwind cleared them; a
guarded reopen on the same allocation graph saw none and traffic resumed.
A physically stuck DMA engine was not tested.

Source review found that a successful open could leave RX ungated on
a later non-mailbox reset. Arm the VF receive gate before rebuilding
the datapath and clear it only after the final mailbox-state check.
Discard cached registration and PF link state when replacing the
admin channel so a fresh link notification controls carrier.
Later patches install the station address and initial packet filter before
traffic resumes, and schedule secondary address-list replay after open.
Defer ACK transmission off RX dispatch, authenticate PF completions from
CQ metadata, serialize runtime INIT, and update address-list counters
under their synchronization lock.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h         |  28 ++
 drivers/net/ethernet/cisco/enic/enic_admin.c   |  37 +-
 drivers/net/ethernet/cisco/enic/enic_ethtool.c |   5 +
 drivers/net/ethernet/cisco/enic/enic_main.c    | 610 +++++++++++++++++++++----
 drivers/net/ethernet/cisco/enic/enic_mbox.c    | 184 +++++++-
 drivers/net/ethernet/cisco/enic/enic_mbox.h    |   2 +
 drivers/net/ethernet/cisco/enic/enic_rq.c      |  11 +-
 drivers/net/ethernet/cisco/enic/vnic_dev.c     |  21 +-
 drivers/net/ethernet/cisco/enic/vnic_dev.h     |   2 +
 9 files changed, 787 insertions(+), 113 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 2ea2d22373b6..7fddd68e3213 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -254,6 +254,7 @@ struct enic {
 	struct timer_list notify_timer;
 	struct work_struct reset;
 	struct work_struct tx_hang_reset;
+	struct work_struct vf_mbox_recovery_work;
 	struct work_struct change_mtu_work;
 	struct msix_entry *msix_entry;
 	struct enic_msix_entry *msix;
@@ -314,6 +315,29 @@ struct enic {
 	enum enic_admin_chan_state admin_chan_state;
 	/* Blocks sends throughout close, partial open and timeout recovery. */
 	bool mbox_send_disabled;
+	/* A send timeout leaves WQ descriptor ownership unresolved until channel
+	 * shutdown proves that both admin queues stopped.
+	 */
+	bool mbox_tx_poisoned;
+	/* After a lost or inconsistent reply, the VF cannot know whether the PF
+	 * applied the request. Reconnect during the next open or reset.
+	 */
+	bool vf_mbox_reconnect_required;
+	/* Prevent a mailbox fault from scheduling another worker during
+	 * recovery. A failed recovery remains quarantined until a later
+	 * external recovery event or close/open.
+	 */
+	bool vf_mbox_recovery_active;
+	/* Detect a new fault during VF re-registration before clearing the
+	 * reconnect-required state.
+	 */
+	u32 vf_mbox_fault_generation;
+	/* One slow-path-owned predicate keeps the RX hot path fail-closed while
+	 * VF registration is lost or receive state may not match the PF.
+	 */
+	bool vf_rx_quarantined;
+	/* RTNL protects software open/stop pairing; this does not prove DMA stop. */
+	bool datapath_open;
 	struct vnic_wq admin_wq;
 	struct vnic_rq admin_rq;
 	struct vnic_cq admin_cq[2];
@@ -345,6 +369,10 @@ struct enic {
 	struct completion mbox_comp;
 	struct mutex vf_mbox_request_lock; /* serializes VF request lifetimes */
 	spinlock_t mbox_state_lock;	/* protects expected reply state */
+	spinlock_t vf_ack_lock;		/* protects vf_ack_list */
+	struct list_head vf_ack_list;
+	struct work_struct vf_ack_work;
+	unsigned int vf_ack_count;
 	u64 mbox_expected_msg_num;
 	u8 mbox_expected_reply;
 	bool mbox_initialized;
diff --git a/drivers/net/ethernet/cisco/enic/enic_admin.c b/drivers/net/ethernet/cisco/enic/enic_admin.c
index d4f3f58a0ec2..8b36dadb6463 100644
--- a/drivers/net/ethernet/cisco/enic/enic_admin.c
+++ b/drivers/net/ethernet/cisco/enic/enic_admin.c
@@ -134,14 +134,22 @@ unsigned int enic_admin_wq_cq_service(struct enic *enic)
  */
 #define ENIC_ADMIN_MSG_MAX	256
 
+static void enic_admin_rx_lost(struct enic *enic)
+{
+	if (enic_is_sriov_vf_v2(enic))
+		enic_mbox_vf_require_reconnect(enic);
+}
+
 static void enic_admin_msg_enqueue(struct enic *enic, void *buf,
 				   unsigned int len)
 {
 	struct enic_admin_msg *msg;
 
 	msg = kmalloc_flex(*msg, data, len);
-	if (!msg)
+	if (!msg) {
+		enic_admin_rx_lost(enic);
 		return;
+	}
 
 	msg->len = len;
 	memcpy(msg->data, buf, len);
@@ -154,6 +162,7 @@ static void enic_admin_msg_enqueue(struct enic *enic, void *buf,
 			netdev_warn(enic->netdev,
 				    "admin msg backlog full (%u); dropping\n",
 				    ENIC_ADMIN_MSG_MAX);
+		enic_admin_rx_lost(enic);
 		return;
 	}
 	list_add_tail(&msg->list, &enic->admin_msg_list);
@@ -167,6 +176,7 @@ unsigned int enic_admin_rq_cq_service(struct enic *enic)
 	struct vnic_rq *rq = &enic->admin_rq;
 	struct cq_enet_rq_desc *rq_desc;
 	struct vnic_rq_buf *buf;
+	u16 sender_vlan;
 	u16 bwf, bytes_written;
 	unsigned int work = 0;
 	void *desc;
@@ -186,6 +196,14 @@ unsigned int enic_admin_rq_cq_service(struct enic *enic)
 		 */
 		dma_rmb();
 		buf = rq->to_clean;
+		rq_desc = desc;
+		sender_vlan = le16_to_cpu(rq_desc->vlan);
+
+		/* A V2 VF's only valid admin-channel peer is its PF. Drop any
+		 * other sender before malformed CQ state can trigger recovery.
+		 */
+		if (enic_is_sriov_vf_v2(enic) && sender_vlan != 0)
+			goto next_desc;
 
 		/* Decode the actual number of bytes hardware wrote into
 		 * the RX buffer.  buf->len is the static allocation size
@@ -193,11 +211,12 @@ unsigned int enic_admin_rq_cq_service(struct enic *enic)
 		 * beyond the actual DMA payload.  bytes_written_flags is at
 		 * the same offset in every cq_enet_rq_desc[_32|_64] variant.
 		 */
-		rq_desc = desc;
 		bwf = le16_to_cpu(rq_desc->bytes_written_flags);
 		bytes_written = bwf & CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK;
-		if (bytes_written > buf->len)
+		if (bytes_written > buf->len) {
+			enic_admin_rx_lost(enic);
 			goto next_desc;
+		}
 
 		dma_sync_single_for_cpu(&enic->pdev->dev,
 					buf->dma_addr, buf->len,
@@ -212,23 +231,22 @@ unsigned int enic_admin_rq_cq_service(struct enic *enic)
 		if (bwf & CQ_ENET_RQ_DESC_FLAGS_TRUNCATED) {
 			netdev_warn_once(enic->netdev,
 					 "admin RQ: truncated message dropped\n");
+			enic_admin_rx_lost(enic);
 			goto next_desc;
 		}
 		if (!(rq_desc->flags & CQ_ENET_RQ_DESC_FLAGS_FCS_OK)) {
 			netdev_warn_once(enic->netdev,
 					 "admin RQ: bad FCS, dropping message\n");
+			enic_admin_rx_lost(enic);
 			goto next_desc;
 		}
 
 		if (enic->admin_rq_handler) {
-			u16 sender_vlan;
-
 			/* Firmware sets the CQ VLAN field to identify the
 			 * sender: 0 = PF, 1-based = VF index.  Overwrite
 			 * the untrusted src_vnic_id in the MBOX header with
 			 * the hardware-verified value.
 			 */
-			sender_vlan = le16_to_cpu(rq_desc->vlan);
 			if (bytes_written >= sizeof(struct enic_mbox_hdr)) {
 				struct enic_mbox_hdr *hdr = buf->os_buf;
 
@@ -726,6 +744,11 @@ int enic_admin_channel_close(struct enic *enic)
 		enic_admin_teardown_intr(enic);
 		cancel_work_sync(&enic->link_notify_work);
 		cancel_work_sync(&enic->admin_msg_work);
+		/* admin_msg_work is the sole VF ACK producer. Drain it before
+		 * the ACK worker so no producer can race the final purge.
+		 */
+		if (enic_is_sriov_vf_v2(enic))
+			enic_mbox_vf_ack_cancel(enic);
 		enic_admin_msg_drain(enic);
 	}
 
@@ -771,6 +794,7 @@ int enic_admin_channel_close(struct enic *enic)
 	}
 
 	enic_admin_channel_release(enic);
+	WRITE_ONCE(enic->mbox_tx_poisoned, false);
 	mutex_unlock(&enic->mbox_lock);
 
 	/* Firmware rejection does not undermine the WQ/RQ proof. */
@@ -797,6 +821,7 @@ int enic_admin_channel_final_recheck(struct enic *enic)
 	}
 
 	enic_admin_channel_release(enic);
+	WRITE_ONCE(enic->mbox_tx_poisoned, false);
 	mutex_unlock(&enic->mbox_lock);
 	netdev_info(enic->netdev,
 		    "Admin queues stopped during final teardown; releasing DMA graph\n");
diff --git a/drivers/net/ethernet/cisco/enic/enic_ethtool.c b/drivers/net/ethernet/cisco/enic/enic_ethtool.c
index 61541fb8db7b..d69963755b6b 100644
--- a/drivers/net/ethernet/cisco/enic/enic_ethtool.c
+++ b/drivers/net/ethernet/cisco/enic/enic_ethtool.c
@@ -381,6 +381,9 @@ static int enic_set_ringparam(struct net_device *netdev,
 	unsigned int tx_pending;
 	int err = 0;
 
+	if (!netif_device_present(netdev))
+		return -ENODEV;
+
 	if (ring->rx_mini_max_pending || ring->rx_mini_pending) {
 		netdev_info(netdev,
 			    "modifying mini ring params is not supported");
@@ -409,6 +412,8 @@ static int enic_set_ringparam(struct net_device *netdev,
 	}
 	if (running)
 		dev_close(netdev);
+	if (!netif_device_present(netdev))
+		return -ENODEV;
 	c->rq_desc_count =
 		ring->rx_pending & 0xffffffe0; /* must be aligned to groups of 32 */
 	c->wq_desc_count =
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index dde9098357d1..587c340854cb 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1038,12 +1038,13 @@ void enic_reset_addr_lists(struct enic *enic)
 {
 	struct net_device *netdev = enic->netdev;
 
+	netif_addr_lock_bh(netdev);
 	__dev_uc_unsync(netdev, NULL);
 	__dev_mc_unsync(netdev, NULL);
-
 	enic->mc_count = 0;
 	enic->uc_count = 0;
 	enic->flags = 0;
+	netif_addr_unlock_bh(netdev);
 }
 
 static int enic_set_mac_addr(struct net_device *netdev, char *addr)
@@ -1718,11 +1719,20 @@ static void enic_notify_timer_start(struct enic *enic)
 	}
 }
 
-/* rtnl lock is held, process context */
+static int enic_admin_chan_reopen(struct enic *enic);
+
+static void enic_detach_after_recovery_failure(struct enic *enic)
+{
+	netif_device_detach(enic->netdev);
+	netif_carrier_off(enic->netdev);
+}
+
 static int enic_open(struct net_device *netdev)
 {
 	struct enic *enic = netdev_priv(netdev);
+	bool clear_cqs = false;
 	unsigned int i;
+	int stop_err = 0;
 	int err, ret;
 	unsigned int max_pkt_len = netdev->mtu + VLAN_ETH_HLEN;
 	struct page_pool_params pp_params = {
@@ -1739,9 +1749,43 @@ static int enic_open(struct net_device *netdev)
 	/* Internal reopen paths also bypass the networking core's presence check. */
 	if (!netif_device_present(netdev))
 		return -ENODEV;
+	if (enic_is_sriov_vf_v2(enic)) {
+		WRITE_ONCE(enic->vf_rx_quarantined, true);
+		if (enic_admin_channel_is_quarantined(enic))
+			return -EBUSY;
+	}
+
+	/* A reply timeout invalidates the current request generation. Rebuild and
+	 * re-register before allocating datapath resources. A send timeout also
+	 * enters this path. Close releases it only after both queues stop;
+	 * otherwise it is retained for the final remove-time recheck.
+	 */
 	if (enic_is_sriov_vf_v2(enic) &&
-	    enic_admin_channel_is_quarantined(enic))
-		return -EBUSY;
+	    (READ_ONCE(enic->admin_chan_state) != ENIC_ADMIN_CHAN_LIVE ||
+	     READ_ONCE(enic->mbox_tx_poisoned) ||
+	     !READ_ONCE(enic->vf_registered) ||
+	     READ_ONCE(enic->vf_mbox_reconnect_required))) {
+		/* Re-registration makes the PF discard the old VF-requested
+		 * filters.  Clear the netdev-core synchronization state so the
+		 * receive-mode callback replays the current address lists.
+		 */
+		enic_reset_addr_lists(enic);
+		err = 0;
+		if (READ_ONCE(enic->admin_chan_state) != ENIC_ADMIN_CHAN_DOWN)
+			err = enic_admin_channel_close(enic);
+
+		/* Close has drained replies and link notifications from the
+		 * old channel. Discard their state even on a stop failure.
+		 */
+		WRITE_ONCE(enic->vf_registered, false);
+		enic_mbox_vf_link_state_reset(enic);
+		if (READ_ONCE(enic->admin_chan_state) != ENIC_ADMIN_CHAN_DOWN)
+			return err ?: -EBUSY;
+
+		err = enic_admin_chan_reopen(enic);
+		if (err)
+			return err;
+	}
 
 	err = enic_request_intr(enic);
 	if (err) {
@@ -1801,17 +1845,45 @@ static int enic_open(struct net_device *netdev)
 		netdev_err(netdev, "Failed to enable device: %d\n", err);
 		goto err_out_dev_enable;
 	}
+	if (enic_is_sriov_vf_v2(enic)) {
+		/* Keep RX gated until the final mailbox check. Hold the state
+		 * lock through the carrier transition so a later fault wins.
+		 */
+		spin_lock_bh(&enic->mbox_state_lock);
+		if (!READ_ONCE(enic->vf_registered) ||
+		    READ_ONCE(enic->mbox_send_disabled) ||
+		    READ_ONCE(enic->mbox_tx_poisoned) ||
+		    READ_ONCE(enic->vf_mbox_reconnect_required)) {
+			err = -EIO;
+		} else {
+			WRITE_ONCE(enic->vf_rx_quarantined, false);
+			enic_mbox_vf_link_state_set_running(enic, true);
+		}
+		spin_unlock_bh(&enic->mbox_state_lock);
+		if (err) {
+			netdev_err(netdev,
+				   "MBOX state changed during VF datapath open\n");
+			goto err_out_dev_disable;
+		}
+	}
 
 	for (i = 0; i < enic->intr_count; i++)
 		vnic_intr_unmask(&enic->intr[i]);
-
 	enic_notify_timer_start(enic);
 	enic_rfs_timer_start(enic);
-	if (enic_is_sriov_vf_v2(enic))
-		enic_mbox_vf_link_state_set_running(enic, true);
+	WRITE_ONCE(enic->datapath_open, true);
 
 	return 0;
 
+err_out_dev_disable:
+	/* The only caller reached this label after CMD_ENABLE succeeded. */
+	for (i = 0; i < enic->intr_count; i++) {
+		vnic_intr_mask(&enic->intr[i]);
+		(void)vnic_intr_masked(&enic->intr[i]);
+	}
+	enic_synchronize_irqs(enic);
+	clear_cqs = true;
+	enic_dev_disable(enic);
 err_out_dev_enable:
 	for (i = 0; i < enic->rq_count; i++)
 		napi_disable(&enic->napi[i]);
@@ -1821,8 +1893,11 @@ static int enic_open(struct net_device *netdev)
 	netif_tx_disable(netdev);
 	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
 		enic_dev_del_station_addr(enic);
-	for (i = 0; i < enic->wq_count; i++)
-		vnic_wq_disable(&enic->wq[i].vwq);
+	for (i = 0; i < enic->wq_count; i++) {
+		ret = vnic_wq_disable(&enic->wq[i].vwq);
+		if (ret)
+			stop_err = ret;
+	}
 err_out_free_rq:
 	for (i = 0; i < enic->rq_count; i++) {
 		ret = vnic_rq_disable(&enic->rq[i].vrq);
@@ -1830,8 +1905,21 @@ static int enic_open(struct net_device *netdev)
 			vnic_rq_clean(&enic->rq[i].vrq, enic_free_rq_buf);
 			page_pool_destroy(enic->rq[i].pool);
 			enic->rq[i].pool = NULL;
+		} else {
+			stop_err = ret;
 		}
 	}
+	if (stop_err) {
+		enic_detach_after_recovery_failure(enic);
+	} else if (clear_cqs) {
+		/* Every generic WQ/RQ stopped; old completions cannot be reused. */
+		for (i = 0; i < enic->wq_count; i++)
+			vnic_wq_clean(&enic->wq[i].vwq, enic_free_wq_buf);
+		for (i = 0; i < enic->cq_count; i++)
+			vnic_cq_clean(&enic->cq[i]);
+		for (i = 0; i < enic->intr_count; i++)
+			vnic_intr_clean(&enic->intr[i]);
+	}
 	enic_dev_notify_unset(enic);
 err_out_free_intr:
 	enic_unset_affinity_hint(enic);
@@ -1841,12 +1929,17 @@ static int enic_open(struct net_device *netdev)
 }
 
 /* rtnl lock is held, process context */
-static int enic_stop(struct net_device *netdev)
+static int __enic_stop(struct net_device *netdev)
 {
 	struct enic *enic = netdev_priv(netdev);
 	unsigned int i;
 	int err;
 
+	/* IFF_UP can outlive a failed internal recovery. Stop software once. */
+	if (!READ_ONCE(enic->datapath_open))
+		return 0;
+	WRITE_ONCE(enic->datapath_open, false);
+
 	for (i = 0; i < enic->intr_count; i++) {
 		vnic_intr_mask(&enic->intr[i]);
 		(void)vnic_intr_masked(&enic->intr[i]); /* flush write */
@@ -1871,23 +1964,25 @@ static int enic_stop(struct net_device *netdev)
 			napi_disable(&enic->napi[enic_cq_wq(enic, i)]);
 	netif_tx_disable(netdev);
 
+	/* Detach IRQ callbacks even if a later queue disable fails. */
+	enic_unset_affinity_hint(enic);
+	enic_free_intr(enic);
+
 	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
 		enic_dev_del_station_addr(enic);
 
 	for (i = 0; i < enic->wq_count; i++) {
 		err = vnic_wq_disable(&enic->wq[i].vwq);
 		if (err)
-			return err;
+			goto stop_failed;
 	}
 	for (i = 0; i < enic->rq_count; i++) {
 		err = vnic_rq_disable(&enic->rq[i].vrq);
 		if (err)
-			return err;
+			goto stop_failed;
 	}
 
 	enic_dev_notify_unset(enic);
-	enic_unset_affinity_hint(enic);
-	enic_free_intr(enic);
 
 	for (i = 0; i < enic->wq_count; i++)
 		vnic_wq_clean(&enic->wq[i].vwq, enic_free_wq_buf);
@@ -1902,6 +1997,18 @@ static int enic_stop(struct net_device *netdev)
 		vnic_intr_clean(&enic->intr[i]);
 
 	return 0;
+
+stop_failed:
+	/* Prevent another open from treating this partial stop as a clean one.
+	 * Generic queue DMA lifetime after a stop failure is separate work.
+	 */
+	enic_detach_after_recovery_failure(enic);
+	return err;
+}
+
+static int enic_stop(struct net_device *netdev)
+{
+	return __enic_stop(netdev);
 }
 
 static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
@@ -2036,12 +2143,81 @@ static int enic_dev_open(struct enic *enic)
 	return err;
 }
 
+static int enic_dev_hang_reset_start(struct vnic_dev *vdev, int arg)
+{
+	struct enic *enic = vnic_dev_priv(vdev);
+	u64 a0 = (u32)arg, a1 = 0;
+	int err;
+
+	/* A V2 VF recovers with the hang-reset pair; issue CMD_HANG_RESET
+	 * directly to skip the generic helper's CMD_CAPABILITY round-trip on
+	 * the VF command path.
+	 */
+	spin_lock_bh(&enic->devcmd_lock);
+	if (enic_is_sriov_vf_v2(enic))
+		err = vnic_dev_cmd(vdev, CMD_HANG_RESET, &a0, &a1, 1000);
+	else
+		err = vnic_dev_hang_reset(vdev, arg);
+	spin_unlock_bh(&enic->devcmd_lock);
+
+	return err;
+}
+
+static int enic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
+{
+	struct enic *enic = vnic_dev_priv(vdev);
+	u64 a0 = 0, a1 = 0;
+	int err;
+
+	*done = 0;
+	spin_lock_bh(&enic->devcmd_lock);
+	if (enic_is_sriov_vf_v2(enic)) {
+		err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS, &a0, &a1, 1000);
+		if (!err)
+			*done = a0 == 0;
+	} else {
+		err = vnic_dev_hang_reset_done(vdev, done);
+	}
+	spin_unlock_bh(&enic->devcmd_lock);
+
+	return err;
+}
+
+/* The soft-reset poll shares the device-command registers with statistics and
+ * other netdev operations; serialize each step under devcmd_lock, matching the
+ * hang-reset and runtime-init paths.  Otherwise a concurrent CMD_STATS_DUMP can
+ * collide on the shared registers and make a reset spuriously report failure.
+ */
+static int enic_dev_soft_reset_start(struct vnic_dev *vdev, int arg)
+{
+	struct enic *enic = vnic_dev_priv(vdev);
+	int err;
+
+	spin_lock_bh(&enic->devcmd_lock);
+	err = vnic_dev_soft_reset(vdev, arg);
+	spin_unlock_bh(&enic->devcmd_lock);
+
+	return err;
+}
+
+static int enic_dev_soft_reset_done(struct vnic_dev *vdev, int *done)
+{
+	struct enic *enic = vnic_dev_priv(vdev);
+	int err;
+
+	spin_lock_bh(&enic->devcmd_lock);
+	err = vnic_dev_soft_reset_done(vdev, done);
+	spin_unlock_bh(&enic->devcmd_lock);
+
+	return err;
+}
+
 static int enic_dev_soft_reset(struct enic *enic)
 {
 	int err;
 
-	err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
-			    vnic_dev_soft_reset_done, 0);
+	err = enic_dev_wait(enic->vdev, enic_dev_soft_reset_start,
+			    enic_dev_soft_reset_done, 0);
 	if (err)
 		netdev_err(enic->netdev, "vNIC soft reset failed, err %d\n",
 			   err);
@@ -2049,12 +2225,17 @@ static int enic_dev_soft_reset(struct enic *enic)
 	return err;
 }
 
-static int enic_dev_hang_reset(struct enic *enic)
+static int enic_dev_hang_reset(struct enic *enic, bool *needs_init)
 {
 	int err;
 
-	err = enic_dev_wait(enic->vdev, vnic_dev_hang_reset,
-		vnic_dev_hang_reset_done, 0);
+	*needs_init = false;
+	err = enic_dev_wait(enic->vdev, enic_dev_hang_reset_start,
+			    enic_dev_hang_reset_done, 0);
+	if (!err && !enic_is_sriov_vf_v2(enic)) {
+		*needs_init =
+			vnic_dev_hang_reset_uses_soft_reset(enic->vdev);
+	}
 	if (err)
 		netdev_err(enic->netdev, "vNIC hang reset failed, err %d\n",
 			err);
@@ -2062,6 +2243,21 @@ static int enic_dev_hang_reset(struct enic *enic)
 	return err;
 }
 
+static int enic_vnic_dev_init(struct enic *enic)
+{
+	int err;
+
+	/* Runtime init shares the device-command registers with statistics and
+	 * other netdev operations. Probe-time init has no concurrent callers and
+	 * intentionally remains direct.
+	 */
+	spin_lock_bh(&enic->devcmd_lock);
+	err = vnic_dev_init(enic->vdev, 0);
+	spin_unlock_bh(&enic->devcmd_lock);
+
+	return err;
+}
+
 int __enic_set_rsskey(struct enic *enic)
 {
 	union vnic_rss_key *rss_key_buf_va;
@@ -2209,18 +2405,17 @@ static bool enic_control_dma_unresolved(struct enic *enic)
 	       READ_ONCE(enic->sriov_stats_dma_unresolved);
 }
 
-/* Re-establish the admin/MBOX channel after a reset has re-created the data
- * path.  Mirrors the relevant part of the probe / SR-IOV-enable sequence:
- * reinitialise MBOX and reopen the channel, then for a VF re-run the PF
- * handshake (the reset wiped the VF's admin QP, so the VF must register
- * again), or for a PF re-push the current link state to registered VFs.
+/* Rebuild the admin channel and VF registration before VF datapath open.
+ * The PF calls this after datapath open to replay its current link state.
+ * Return an error if the channel or the VF handshake fails.
  */
-static void enic_admin_chan_reopen(struct enic *enic)
+static int enic_admin_chan_reopen(struct enic *enic)
 {
+	u32 recovery_generation = 0;
 	int err;
 
-	if (enic_admin_channel_is_quarantined(enic))
-		return;
+	if (enic_control_dma_unresolved(enic))
+		return -EBUSY;
 
 	/* Install the MBOX receive handler and clear pending reply state before
 	 * opening the channel, so the handler is in place before the admin
@@ -2238,31 +2433,62 @@ static void enic_admin_chan_reopen(struct enic *enic)
 	 */
 	if (enic_is_sriov_vf_v2(enic))
 		WRITE_ONCE(enic->vf_registered, false);
+	if (enic_is_sriov_vf_v2(enic)) {
+		spin_lock_bh(&enic->mbox_state_lock);
+		recovery_generation = enic->vf_mbox_fault_generation;
+		spin_unlock_bh(&enic->mbox_state_lock);
+	}
 
 	err = enic_admin_channel_open(enic);
 	if (err) {
 		netdev_err(enic->netdev,
 			   "admin channel reopen after reset failed: %d\n", err);
-		return;
+		return err;
 	}
 
 	if (enic_is_sriov_vf_v2(enic)) {
 		err = enic_mbox_vf_capability_check(enic);
 		if (err) {
+			int close_err;
+
 			netdev_err(enic->netdev,
 				   "MBOX capability check after reset failed: %d\n",
 				   err);
-			enic_admin_channel_close(enic);
+			close_err = enic_admin_channel_close(enic);
 			WRITE_ONCE(enic->vf_registered, false);
-			return;
+			return close_err ?: err;
 		}
 		err = enic_mbox_vf_register(enic);
 		if (err) {
+			int close_err;
+
 			netdev_err(enic->netdev,
 				   "MBOX VF re-registration after reset failed: %d\n",
 				   err);
-			enic_admin_channel_close(enic);
+			close_err = enic_admin_channel_close(enic);
+			WRITE_ONCE(enic->vf_registered, false);
+			return close_err ?: err;
+		}
+		enic_reset_addr_lists(enic);
+		/* The handshake establishes a new protocol generation.
+		 * Keep RX gated until the final open check.
+		 */
+		spin_lock_bh(&enic->mbox_state_lock);
+		if (enic->vf_mbox_fault_generation != recovery_generation ||
+		    READ_ONCE(enic->mbox_tx_poisoned)) {
+			err = -EAGAIN;
+		} else {
+			WRITE_ONCE(enic->vf_mbox_reconnect_required, false);
+		}
+		spin_unlock_bh(&enic->mbox_state_lock);
+		if (err) {
+			int close_err;
+
+			netdev_warn(enic->netdev,
+				    "MBOX state changed during VF re-registration\n");
+			close_err = enic_admin_channel_close(enic);
 			WRITE_ONCE(enic->vf_registered, false);
+			return close_err ?: err;
 		}
 	} else {
 		/* The link came back up during enic_open() above while MBOX
@@ -2271,135 +2497,343 @@ static void enic_admin_chan_reopen(struct enic *enic)
 		 */
 		schedule_work(&enic->link_notify_work);
 	}
+
+	return 0;
+}
+
+static bool enic_vf_mbox_recovery_begin(struct enic *enic,
+					bool mailbox_recovery)
+{
+	bool claimed = false;
+
+	/* Reset workers claim ownership only after taking RTNL. This state
+	 * lock still makes the handoff atomic with mailbox fault producers.
+	 */
+	spin_lock_bh(&enic->mbox_state_lock);
+	/* Open may have consumed a queued mailbox fault while holding RTNL. */
+	if (!enic->vf_mbox_recovery_active &&
+	    (!mailbox_recovery ||
+	     READ_ONCE(enic->vf_mbox_reconnect_required) ||
+	     READ_ONCE(enic->mbox_tx_poisoned))) {
+		enic->vf_mbox_recovery_active = true;
+		WRITE_ONCE(enic->vf_rx_quarantined, true);
+		claimed = true;
+	}
+	spin_unlock_bh(&enic->mbox_state_lock);
+
+	return claimed;
+}
+
+static bool enic_vf_mbox_recovery_finish(struct enic *enic, bool succeeded)
+{
+	bool restart;
+
+	spin_lock_bh(&enic->mbox_state_lock);
+	/* Restart only for a fault still outstanding after recovery. Fresh
+	 * registration may already have consumed a fault from the old channel.
+	 * A failed handshake remains quarantined for an external recovery event.
+	 */
+	restart = succeeded &&
+		  (READ_ONCE(enic->vf_mbox_reconnect_required) ||
+		   READ_ONCE(enic->mbox_tx_poisoned));
+	enic->vf_mbox_recovery_active = false;
+	spin_unlock_bh(&enic->mbox_state_lock);
+
+	return restart;
 }
 
 static void enic_reset(struct work_struct *work)
 {
 	struct enic *enic = container_of(work, struct enic, reset);
+	bool recovery_owned = false;
+	bool restart = false;
+	bool reopen;
+	int stop_err = 0;
+	int err = 0;
 
 	if (!netif_running(enic->netdev))
 		return;
-
 	rtnl_lock();
-
-	if (!netif_running(enic->netdev))
+	reopen = netif_running(enic->netdev);
+	if (!reopen || !netif_device_present(enic->netdev))
 		goto unlock;
 
-	/* Stop any activity from infiniband */
+	/* Serialize a live V2 VF protocol recovery and preserve its one bounded
+	 * late-fault follow-up.
+	 */
+	if (reopen && enic_is_sriov_vf_v2(enic)) {
+		recovery_owned = enic_vf_mbox_recovery_begin(enic, false);
+		if (!recovery_owned)
+			goto unlock;
+	}
+
+	/* Stop any activity from infiniband. */
 	enic_set_api_busy(enic, true);
 
-	/* Close the V2 admin/MBOX channel before the soft reset. Release its
-	 * DMA resources only after both queues report stopped; otherwise
-	 * quarantine the channel and abandon the reset.
+	/* Close the admin channel before reset without sending DEL_MAC; reset and
+	 * fresh registration discard the old VF-requested state. Release its DMA
+	 * resources only after both queues report stopped. Otherwise quarantine
+	 * the channel and abandon the reset.
 	 */
 	if (enic_has_admin_chan(enic)) {
-		enic_admin_channel_close(enic);
+		int close_err = enic_admin_channel_close(enic);
+
+		if (close_err && enic_admin_channel_is_quarantined(enic))
+			netdev_err(enic->netdev,
+				   "Admin queue did not stop: %d\n", close_err);
+		else if (close_err)
+			netdev_warn(enic->netdev,
+				    "Admin QP disable returned: %d\n",
+				    close_err);
 		/* Channel close has drained registration replies. */
 		if (enic_is_sriov_vf_v2(enic))
 			WRITE_ONCE(enic->vf_registered, false);
 	}
-	if (enic_admin_channel_is_quarantined(enic)) {
-		/* Core close excludes netpoll and clears __LINK_STATE_START first. */
-		dev_close(enic->netdev);
-		goto reset_out;
-	}
+	if (READ_ONCE(enic->datapath_open))
+		stop_err = __enic_stop(enic->netdev);
 
-	enic_stop(enic->netdev);
 	if (enic_is_sriov_vf_v2(enic))
 		enic_mbox_vf_link_state_reset(enic);
+	if (stop_err || enic_control_dma_unresolved(enic)) {
+		err = stop_err ?: -EBUSY;
+		netdev_err(enic->netdev,
+			   "Recovery blocked after close (datapath stop %d)\n",
+			   stop_err);
+		goto reset_out;
+	}
+
+	err = enic_dev_soft_reset(enic);
+	if (err) {
+		enic_detach_after_recovery_failure(enic);
+		goto reset_out;
+	}
+	/* Firmware completes SOFT_RESET in OPEN state.  Non-dynamic vNICs need
+	 * CMD_INIT to recreate and enable their LIF before resource restore.
+	 */
+	if (!enic_is_dynamic(enic)) {
+		err = enic_vnic_dev_init(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "vNIC init after soft reset failed: %d\n",
+				   err);
+			enic_detach_after_recovery_failure(enic);
+			goto reset_out;
+		}
+	}
 
-	enic_dev_soft_reset(enic);
 	enic_reset_addr_lists(enic);
 	enic_init_vnic_resources(enic);
 	enic_set_rss_nic_cfg(enic);
 	enic_dev_set_ig_vlan_rewrite_mode(enic);
 	enic_ext_cq(enic);
 
-	if (enic_open(enic->netdev))
+	/* A V2 VF registers with the PF before reopening its datapath.
+	 * A V2 PF rebuilds its admin channel after datapath open.
+	 */
+	if (enic_is_sriov_vf_v2(enic)) {
+		err = enic_admin_chan_reopen(enic);
+		if (err)
+			goto reset_out;
+	}
+
+	if (reopen)
+		err = enic_open(enic->netdev);
+	if (reopen && err) {
+		if (enic_is_sriov_vf_v2(enic) && enic_has_admin_chan(enic)) {
+			int close_err = enic_admin_channel_close(enic);
+
+			WRITE_ONCE(enic->vf_registered, false);
+			if (close_err)
+				netdev_warn(enic->netdev,
+					    "Admin close after datapath reopen failure returned: %d\n",
+					    close_err);
+		}
+		netdev_err(enic->netdev,
+			   "Failed to reopen datapath after reset: %d\n", err);
 		goto reset_out;
+	}
 
-	/* Re-establish the admin/MBOX channel after the data path is back up.
-	 * It was fully torn down by enic_admin_channel_close() above;
-	 * enic_admin_chan_reopen() reopens it and, for a PF re-pushes link
-	 * state, or for a VF re-runs the probe-time PF handshake.
+	/* A PF reopens its admin channel after the datapath and re-pushes link
+	 * state.  The VF handshake, which open depends on, completed above.
 	 */
-	if (enic_has_admin_chan(enic))
-		enic_admin_chan_reopen(enic);
-	if (enic_is_sriov_vf_v2(enic) &&
-	    enic_admin_channel_is_quarantined(enic))
-		dev_close(enic->netdev);
+	if (enic_has_admin_chan(enic) && !enic_is_sriov_vf_v2(enic)) {
+		int admin_err = enic_admin_chan_reopen(enic);
+
+		if (admin_err)
+			netdev_err(enic->netdev,
+				   "Failed to reopen PF admin channel after reset: %d\n",
+				   admin_err);
+		if (!err)
+			err = admin_err;
+	}
 
 reset_out:
 	/* Allow infiniband to fiddle with the device again */
 	enic_set_api_busy(enic, false);
 
-	call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+	if (reopen)
+		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
 
 unlock:
+	if (recovery_owned)
+		restart = enic_vf_mbox_recovery_finish(enic,
+						       !err &&
+						       !enic_control_dma_unresolved(enic));
 	rtnl_unlock();
+	if (restart)
+		schedule_work(&enic->vf_mbox_recovery_work);
 }
 
-static void enic_tx_hang_reset(struct work_struct *work)
+static void enic_hang_reset(struct enic *enic, bool mailbox_recovery)
 {
-	struct enic *enic = container_of(work, struct enic, tx_hang_reset);
+	bool recovery_owned = false;
+	bool restart = false;
+	bool needs_init;
+	bool reopen;
+	int stop_err = 0;
+	int err = 0;
 
 	rtnl_lock();
-
-	if (!netif_running(enic->netdev))
+	reopen = netif_running(enic->netdev);
+	if (!reopen || !netif_device_present(enic->netdev))
 		goto unlock;
+	if (reopen && enic_is_sriov_vf_v2(enic)) {
+		recovery_owned = enic_vf_mbox_recovery_begin(enic,
+							     mailbox_recovery);
+		if (!recovery_owned)
+			goto unlock;
+	}
 
-	/* Stop any activity from infiniband */
+	/* Stop any activity from infiniband. */
 	enic_set_api_busy(enic, true);
 
-	/* Close the V2 admin/MBOX channel before the hang reset. Release its
-	 * DMA resources only after both queues report stopped; otherwise
-	 * quarantine the channel and abandon the reset.
+	/* Report an actual Tx hang before stopping and cleaning its queue. Mailbox
+	 * recovery reuses the VF-allowed hang-reset pair but must not report a
+	 * spurious Tx hang. As in the soft-reset path, skip DEL_MAC because reset
+	 * and fresh registration are the cleanup boundary. Release admin DMA only
+	 * after both queues report stopped; otherwise quarantine the channel and
+	 * abandon the reset.
 	 */
+	if (!mailbox_recovery)
+		enic_dev_hang_notify(enic);
 	if (enic_has_admin_chan(enic)) {
-		enic_admin_channel_close(enic);
+		int close_err = enic_admin_channel_close(enic);
+
+		if (close_err && enic_admin_channel_is_quarantined(enic))
+			netdev_err(enic->netdev,
+				   "Admin queue did not stop: %d\n", close_err);
+		else if (close_err)
+			netdev_warn(enic->netdev,
+				    "Admin QP disable returned: %d\n",
+				    close_err);
 		/* Channel close has drained registration replies. */
 		if (enic_is_sriov_vf_v2(enic))
 			WRITE_ONCE(enic->vf_registered, false);
 	}
-	if (enic_admin_channel_is_quarantined(enic)) {
-		dev_close(enic->netdev);
-		goto reset_out;
-	}
-
-	enic_dev_hang_notify(enic);
-	enic_stop(enic->netdev);
+	if (READ_ONCE(enic->datapath_open))
+		stop_err = __enic_stop(enic->netdev);
 	if (enic_is_sriov_vf_v2(enic))
 		enic_mbox_vf_link_state_reset(enic);
+	if (stop_err || enic_control_dma_unresolved(enic)) {
+		err = stop_err ?: -EBUSY;
+		netdev_err(enic->netdev,
+			   "Recovery blocked after close (datapath stop %d)\n",
+			   stop_err);
+		goto hang_reset_out;
+	}
 
-	enic_dev_hang_reset(enic);
+	err = enic_dev_hang_reset(enic, &needs_init);
+	if (err) {
+		enic_detach_after_recovery_failure(enic);
+		goto hang_reset_out;
+	}
+	/* Native HANG_RESET preserves firmware's desired admin state and the
+	 * firmware reinitializes it.  Only the legacy SOFT_RESET fallback sets
+	 * needs_init and requires the deferred CMD_INIT below.
+	 */
+	if (needs_init && !enic_is_dynamic(enic)) {
+		err = enic_vnic_dev_init(enic);
+		if (err) {
+			netdev_err(enic->netdev,
+				   "vNIC init after hang reset failed: %d\n",
+				   err);
+			enic_detach_after_recovery_failure(enic);
+			goto hang_reset_out;
+		}
+	}
 	enic_reset_addr_lists(enic);
 	enic_init_vnic_resources(enic);
 	enic_set_rss_nic_cfg(enic);
 	enic_dev_set_ig_vlan_rewrite_mode(enic);
 	enic_ext_cq(enic);
 
-	if (enic_open(enic->netdev))
-		goto reset_out;
+	if (enic_is_sriov_vf_v2(enic)) {
+		err = enic_admin_chan_reopen(enic);
+		if (err)
+			goto hang_reset_out;
+	}
+
+	if (reopen)
+		err = enic_open(enic->netdev);
+	if (reopen && err) {
+		if (enic_is_sriov_vf_v2(enic) && enic_has_admin_chan(enic)) {
+			int close_err = enic_admin_channel_close(enic);
 
-	/* Re-establish the admin/MBOX channel after the data path is back up.
-	 * It was fully torn down by enic_admin_channel_close() above;
-	 * enic_admin_chan_reopen() reopens it and, for a PF re-pushes link
-	 * state, or for a VF re-runs the probe-time PF handshake.
+			WRITE_ONCE(enic->vf_registered, false);
+			if (close_err)
+				netdev_warn(enic->netdev,
+					    "Admin close after datapath reopen failure returned: %d\n",
+					    close_err);
+		}
+		netdev_err(enic->netdev,
+			   "Failed to reopen datapath after hang reset: %d\n", err);
+		goto hang_reset_out;
+	}
+
+	/* A PF reopens its admin channel after the datapath and re-pushes link
+	 * state.  The VF handshake, which open depends on, completed above.
 	 */
-	if (enic_has_admin_chan(enic))
-		enic_admin_chan_reopen(enic);
-	if (enic_is_sriov_vf_v2(enic) &&
-	    enic_admin_channel_is_quarantined(enic))
-		dev_close(enic->netdev);
+	if (enic_has_admin_chan(enic) && !enic_is_sriov_vf_v2(enic)) {
+		int admin_err = enic_admin_chan_reopen(enic);
 
-reset_out:
+		if (admin_err)
+			netdev_err(enic->netdev,
+				   "Failed to reopen PF admin channel after hang reset: %d\n",
+				   admin_err);
+		if (!err)
+			err = admin_err;
+	}
+
+hang_reset_out:
 	/* Allow infiniband to fiddle with the device again */
 	enic_set_api_busy(enic, false);
 
-	call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+	if (reopen)
+		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
 
 unlock:
+	if (recovery_owned)
+		restart = enic_vf_mbox_recovery_finish(enic,
+						       !err &&
+						       !enic_control_dma_unresolved(enic));
 	rtnl_unlock();
+	if (restart)
+		schedule_work(&enic->vf_mbox_recovery_work);
+}
+
+static void enic_tx_hang_reset(struct work_struct *work)
+{
+	struct enic *enic = container_of(work, struct enic, tx_hang_reset);
+
+	enic_hang_reset(enic, false);
+}
+
+static void enic_vf_mbox_recovery_work(struct work_struct *work)
+{
+	struct enic *enic = container_of(work, struct enic,
+					vf_mbox_recovery_work);
+
+	enic_hang_reset(enic, true);
 }
 
 static int enic_set_intr_mode(struct enic *enic)
@@ -3289,6 +3723,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	enic_rfs_flw_tbl_init(enic);
 	INIT_WORK(&enic->reset, enic_reset);
 	INIT_WORK(&enic->tx_hang_reset, enic_tx_hang_reset);
+	INIT_WORK(&enic->vf_mbox_recovery_work, enic_vf_mbox_recovery_work);
 	INIT_WORK(&enic->change_mtu_work, enic_change_mtu_work);
 
 	for (i = 0; i < enic->wq_count; i++)
@@ -3465,6 +3900,7 @@ static void enic_remove(struct pci_dev *pdev)
 
 		disable_work_sync(&enic->reset);
 		disable_work_sync(&enic->tx_hang_reset);
+		disable_work_sync(&enic->vf_mbox_recovery_work);
 		disable_work_sync(&enic->change_mtu_work);
 		rtnl_lock();
 		netif_device_detach(netdev);
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
index d1b6f13c8002..3579d2980a24 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c
@@ -18,6 +18,8 @@
 #define ENIC_MBOX_POLL_TIMEOUT_US	5000000
 #define ENIC_MBOX_POLL_INTERVAL_US	100
 
+static void enic_mbox_vf_kick_recovery(struct enic *enic);
+
 static void enic_mbox_fill_hdr(struct enic *enic, struct enic_mbox_hdr *hdr,
 			       u8 msg_type,
 			       u16 dst_vnic_id, u16 msg_len, u64 msg_num)
@@ -43,6 +45,7 @@ static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
 	size_t total_len = sizeof(struct enic_mbox_hdr) + payload_len;
 	struct vnic_wq *wq = &enic->admin_wq;
 	struct wq_enet_desc *desc;
+	bool vf_timeout_recovery = false;
 	bool reply_expected = false;
 	unsigned long timeout;
 	dma_addr_t dma_addr;
@@ -157,7 +160,20 @@ static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
 		 * or free the buffer: the device may still DMA from dma_addr.
 		 * Mark the channel unusable so no further sends are attempted.
 		 */
+		spin_lock_bh(&enic->mbox_state_lock);
 		WRITE_ONCE(enic->mbox_send_disabled, true);
+		WRITE_ONCE(enic->mbox_tx_poisoned, true);
+		if (enic_is_sriov_vf_v2(enic)) {
+			/* The request may have changed PF receive policy even though
+			 * local descriptor ownership is still uncertain. Fail the VF
+			 * closed and do not turn this into an ordinary protocol
+			 * reconnect; the admin-channel lifecycle owns final reclamation.
+			 */
+			WRITE_ONCE(enic->vf_rx_quarantined, true);
+			enic->vf_mbox_fault_generation++;
+			vf_timeout_recovery = true;
+		}
+		spin_unlock_bh(&enic->mbox_state_lock);
 	}
 
 	netdev_dbg(enic->netdev,
@@ -174,6 +190,8 @@ static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
 		spin_unlock_bh(&enic->mbox_state_lock);
 	}
 	mutex_unlock(&enic->mbox_lock);
+	if (vf_timeout_recovery)
+		enic_mbox_vf_kick_recovery(enic);
 	return err;
 }
 
@@ -192,6 +210,105 @@ static int enic_mbox_send_reply(struct enic *enic, u8 msg_type,
 				     payload_len, msg_num, true, 0);
 }
 
+struct enic_mbox_vf_ack {
+	struct list_head list;
+	u64 msg_num;
+	u16 ret_major;
+	u8 msg_type;
+};
+
+static void enic_mbox_vf_ack_work(struct work_struct *work)
+{
+	struct enic *enic = container_of(work, struct enic, vf_ack_work);
+	struct enic_mbox_vf_ack *pending;
+
+	for (;;) {
+		struct enic_mbox_generic_reply ack = {};
+		u8 msg_type;
+		int err;
+
+		spin_lock_bh(&enic->vf_ack_lock);
+		if (list_empty(&enic->vf_ack_list)) {
+			spin_unlock_bh(&enic->vf_ack_lock);
+			break;
+		}
+		pending = list_first_entry(&enic->vf_ack_list,
+					   struct enic_mbox_vf_ack, list);
+		list_del(&pending->list);
+		enic->vf_ack_count--;
+		spin_unlock_bh(&enic->vf_ack_lock);
+
+		if (READ_ONCE(enic->mbox_send_disabled)) {
+			kfree(pending);
+			continue;
+		}
+
+		msg_type = pending->msg_type;
+		ack.ret_major = cpu_to_le16(pending->ret_major);
+		err = enic_mbox_send_reply(enic, msg_type, ENIC_MBOX_DST_PF,
+					   &ack, sizeof(ack), pending->msg_num);
+		kfree(pending);
+		if (err && net_ratelimit())
+			netdev_warn(enic->netdev,
+				    "MBOX: failed to send ACK type %u: %d\n",
+				    msg_type, err);
+	}
+}
+
+static void enic_mbox_vf_queue_ack(struct enic *enic, u8 msg_type,
+				   u64 msg_num, u16 ret_major)
+{
+	struct enic_mbox_vf_ack *pending;
+
+	if (READ_ONCE(enic->mbox_send_disabled))
+		return;
+	pending = kmalloc_obj(*pending, GFP_ATOMIC);
+	if (!pending) {
+		if (net_ratelimit())
+			netdev_warn(enic->netdev,
+				    "MBOX: dropping ACK type %u: no memory\n",
+				    msg_type);
+		return;
+	}
+	pending->msg_num = msg_num;
+	pending->ret_major = ret_major;
+	pending->msg_type = msg_type;
+
+	spin_lock_bh(&enic->vf_ack_lock);
+	if (READ_ONCE(enic->mbox_send_disabled) ||
+	    enic->vf_ack_count >= ENIC_ADMIN_DESC_COUNT) {
+		spin_unlock_bh(&enic->vf_ack_lock);
+		kfree(pending);
+		if (net_ratelimit())
+			netdev_warn(enic->netdev,
+				    "MBOX: dropping ACK type %u: queue unavailable\n",
+				    msg_type);
+		return;
+	}
+	list_add_tail(&pending->list, &enic->vf_ack_list);
+	enic->vf_ack_count++;
+	spin_unlock_bh(&enic->vf_ack_lock);
+	schedule_work(&enic->vf_ack_work);
+}
+
+void enic_mbox_vf_ack_cancel(struct enic *enic)
+{
+	struct enic_mbox_vf_ack *pending, *tmp;
+	LIST_HEAD(discard);
+
+	if (!enic->mbox_initialized)
+		return;
+	cancel_work_sync(&enic->vf_ack_work);
+	spin_lock_bh(&enic->vf_ack_lock);
+	list_splice_init(&enic->vf_ack_list, &discard);
+	enic->vf_ack_count = 0;
+	spin_unlock_bh(&enic->vf_ack_lock);
+	list_for_each_entry_safe(pending, tmp, &discard, list) {
+		list_del(&pending->list);
+		kfree(pending);
+	}
+}
+
 static int enic_mbox_vf_send_request(struct enic *enic, u8 request_type,
 				     u8 expected_reply, void *payload,
 				     u16 payload_len)
@@ -201,6 +318,34 @@ static int enic_mbox_vf_send_request(struct enic *enic, u8 request_type,
 				     expected_reply);
 }
 
+static void enic_mbox_vf_mark_reconnect_locked(struct enic *enic,
+					       bool registration_lost)
+{
+	lockdep_assert_held(&enic->mbox_state_lock);
+
+	if (registration_lost)
+		WRITE_ONCE(enic->vf_registered, false);
+	enic->vf_mbox_fault_generation++;
+	WRITE_ONCE(enic->vf_mbox_reconnect_required, true);
+	WRITE_ONCE(enic->mbox_send_disabled, true);
+	WRITE_ONCE(enic->vf_rx_quarantined, true);
+}
+
+static void enic_mbox_vf_kick_recovery(struct enic *enic)
+{
+	bool schedule = false;
+
+	enic_mbox_vf_link_state_set_running(enic, false);
+
+	spin_lock_bh(&enic->mbox_state_lock);
+	if (!enic->vf_mbox_recovery_active && netif_running(enic->netdev))
+		schedule = true;
+	spin_unlock_bh(&enic->mbox_state_lock);
+
+	if (schedule)
+		schedule_work(&enic->vf_mbox_recovery_work);
+}
+
 static int enic_mbox_wait_reply(struct enic *enic, unsigned long timeout_ms)
 {
 	unsigned long left;
@@ -211,9 +356,9 @@ static int enic_mbox_wait_reply(struct enic *enic, unsigned long timeout_ms)
 	if (left)
 		return 0;
 
-	/* Invalidate a request that the handler has not already accepted.  A
-	 * delayed reply cannot match a later request because message numbers are
-	 * monotonic across channel reopen.
+	/* Invalidate a request that the handler has not already accepted. Whether
+	 * losing the reply invalidates the current protocol generation is an
+	 * operation-specific decision made by the caller.
 	 */
 	spin_lock_bh(&enic->mbox_state_lock);
 	if (enic->mbox_expected_reply) {
@@ -476,9 +621,8 @@ static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload,
 					   u64 msg_num)
 {
 	struct enic_mbox_pf_link_state_notif_msg *notif = payload;
-	struct enic_mbox_pf_link_state_ack_msg ack = {};
 	u32 link_state = le32_to_cpu(notif->link_state);
-	int err;
+	u16 ret_major = 0;
 
 	spin_lock_bh(&enic->vf_link_state_lock);
 	switch (link_state) {
@@ -499,16 +643,16 @@ static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload,
 	default:
 		netdev_warn(enic->netdev, "MBOX: unknown link state %u\n",
 			    link_state);
-		ack.ack.ret_major = cpu_to_le16(ENIC_MBOX_ERR_GENERIC);
+		ret_major = ENIC_MBOX_ERR_GENERIC;
 		break;
 	}
 	spin_unlock_bh(&enic->vf_link_state_lock);
 
-	err = enic_mbox_send_reply(enic, ENIC_MBOX_PF_LINK_STATE_ACK,
-				   ENIC_MBOX_DST_PF, &ack, sizeof(ack), msg_num);
-	if (err && net_ratelimit())
-		netdev_warn(enic->netdev,
-			    "MBOX: failed to send link state ACK: %d\n", err);
+	/* Notification dispatch must not wait behind a synchronous request send:
+	 * its matching reply may be queued behind this notification.
+	 */
+	enic_mbox_vf_queue_ack(enic, ENIC_MBOX_PF_LINK_STATE_ACK, msg_num,
+			       ret_major);
 }
 
 void enic_mbox_vf_link_state_reset(struct enic *enic)
@@ -533,6 +677,17 @@ void enic_mbox_vf_link_state_set_running(struct enic *enic, bool running)
 	spin_unlock_bh(&enic->vf_link_state_lock);
 }
 
+void enic_mbox_vf_require_reconnect(struct enic *enic)
+{
+	/* A fresh REGISTER transaction lets the PF discard any VF-requested
+	 * configuration whose final state became uncertain.
+	 */
+	spin_lock_bh(&enic->mbox_state_lock);
+	enic_mbox_vf_mark_reconnect_locked(enic, false);
+	spin_unlock_bh(&enic->mbox_state_lock);
+	enic_mbox_vf_kick_recovery(enic);
+}
+
 static bool enic_mbox_vf_payload_ok(struct enic *enic, u8 msg_type,
 				    u16 payload_len, size_t min_len)
 {
@@ -608,6 +763,8 @@ static void enic_mbox_recv_handler(struct enic *enic, void *buf,
 			netdev_warn(enic->netdev,
 				    "MBOX: truncated message (len %u < %zu)\n",
 				    len, sizeof(*hdr));
+		if (!enic->vf_state)
+			enic_mbox_vf_require_reconnect(enic);
 		return;
 	}
 
@@ -764,7 +921,12 @@ void enic_mbox_init(struct enic *enic)
 		mutex_init(&enic->vf_mbox_request_lock);
 		init_completion(&enic->mbox_comp);
 		spin_lock_init(&enic->mbox_state_lock);
+		spin_lock_init(&enic->vf_ack_lock);
+		INIT_LIST_HEAD(&enic->vf_ack_list);
+		INIT_WORK(&enic->vf_ack_work, enic_mbox_vf_ack_work);
 		enic->mbox_msg_num = 0;
+		if (enic_is_sriov_vf_v2(enic))
+			WRITE_ONCE(enic->vf_rx_quarantined, true);
 		enic->mbox_initialized = true;
 	} else {
 		reinit_completion(&enic->mbox_comp);
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.h b/drivers/net/ethernet/cisco/enic/enic_mbox.h
index 60409bad2f28..37bc41a900f4 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.h
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.h
@@ -90,6 +90,8 @@ int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
 int enic_mbox_send_link_state(struct enic *enic, u16 vf_id, u32 link_state);
 void enic_mbox_vf_link_state_reset(struct enic *enic);
 void enic_mbox_vf_link_state_set_running(struct enic *enic, bool running);
+void enic_mbox_vf_ack_cancel(struct enic *enic);
+void enic_mbox_vf_require_reconnect(struct enic *enic);
 int enic_mbox_vf_capability_check(struct enic *enic);
 int enic_mbox_vf_register(struct enic *enic);
 int enic_mbox_vf_unregister(struct enic *enic);
diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
index ccbf5c9a21d0..80fe7e819c37 100644
--- a/drivers/net/ethernet/cisco/enic/enic_rq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_rq.c
@@ -330,8 +330,6 @@ static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
 	u16 bytes_written, vlan_tci, checksum;
 	u32 rss_hash;
 
-	rqstats->packets++;
-
 	cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, &ingress_port,
 			    &fcoe, &eop, &sop, &rss_type, &csum_not_calc,
 			    &rss_hash, &bytes_written, &packet_error,
@@ -340,8 +338,15 @@ static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
 			    &tcp_udp_csum_ok, &udp, &tcp, &ipv4_csum_ok, &ipv6,
 			    &ipv4, &ipv4_fragment, &fcs_ok);
 
-	if (enic_rq_pkt_error(rq, packet_error, fcs_ok, bytes_written))
+	if (enic_rq_pkt_error(rq, packet_error, fcs_ok, bytes_written)) {
+		rqstats->packets++;
+		return;
+	}
+	if (unlikely(READ_ONCE(enic->vf_rx_quarantined))) {
+		dev_core_stats_rx_dropped_inc(enic->netdev);
 		return;
+	}
+	rqstats->packets++;
 
 	if (eop && bytes_written > 0) {
 		/* Good receive
diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.c b/drivers/net/ethernet/cisco/enic/vnic_dev.c
index 92eec1455ceb..a78bd58f950f 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_dev.c
+++ b/drivers/net/ethernet/cisco/enic/vnic_dev.c
@@ -721,17 +721,23 @@ int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg)
 {
 	u64 a0 = (u32)arg, a1 = 0;
 	int wait = 1000;
-	int err;
 
+	vdev->hang_reset_uses_soft_reset = false;
 	if (vnic_dev_capable(vdev, CMD_HANG_RESET)) {
 		return vnic_dev_cmd(vdev, CMD_HANG_RESET,
 				&a0, &a1, wait);
-	} else {
-		err = vnic_dev_soft_reset(vdev, arg);
-		if (err)
-			return err;
-		return vnic_dev_init(vdev, 0);
 	}
+
+	/* enic_dev_wait() polls SOFT_RESET_STATUS. INIT follows reset completion
+	 * in the driver, after the ordinary close has succeeded.
+	 */
+	vdev->hang_reset_uses_soft_reset = true;
+	return vnic_dev_soft_reset(vdev, arg);
+}
+
+bool vnic_dev_hang_reset_uses_soft_reset(struct vnic_dev *vdev)
+{
+	return vdev->hang_reset_uses_soft_reset;
 }
 
 int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
@@ -742,6 +748,9 @@ int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
 
 	*done = 0;
 
+	if (vdev->hang_reset_uses_soft_reset)
+		return vnic_dev_soft_reset_done(vdev, done);
+
 	if (vnic_dev_capable(vdev, CMD_HANG_RESET_STATUS)) {
 		err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS,
 				&a0, &a1, wait);
diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.h b/drivers/net/ethernet/cisco/enic/vnic_dev.h
index 6a4d7ce3b636..ca5a9d4bd39d 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_dev.h
+++ b/drivers/net/ethernet/cisco/enic/vnic_dev.h
@@ -95,6 +95,7 @@ struct vnic_dev {
 	dma_addr_t stats_pa;
 	struct vnic_sriov_stats *sriov_stats;
 	dma_addr_t sriov_stats_pa;
+	bool hang_reset_uses_soft_reset;
 	struct vnic_devcmd_fw_info *fw_info;
 	dma_addr_t fw_info_pa;
 	enum vnic_proxy_type proxy;
@@ -160,6 +161,7 @@ int vnic_dev_intr_coal_timer_info(struct vnic_dev *vdev);
 int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg);
 int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg);
 int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done);
+bool vnic_dev_hang_reset_uses_soft_reset(struct vnic_dev *vdev);
 int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done);
 void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
 	enum vnic_dev_intr_mode intr_mode);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH net-next v6 4/7] enic: validate V2 VF configuration replies
  2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
                   ` (2 preceding siblings ...)
  2026-12-04 15:29 ` [PATCH net-next v6 3/7] enic: recover V2 VF mailbox after request failure Satish Kharat
@ 2026-12-04 15:29 ` Satish Kharat
  2026-12-05 16:28   ` netdev-bot+sashiko
  2026-12-04 15:29 ` [PATCH net-next v6 5/7] net: add dev_addr_set_sync() for driver address updates Satish Kharat
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

Add the established V2 mailbox operations for MAC filters and packet-
filter settings, together with the administrative-MAC protocol definitions
and request helpers used by the next patch. Keep request buffers alive
until the VF request completes so detailed replies can be checked entry by
entry.

Validate message framing, echoed operations, result counts, and operation-
specific idempotent results before signaling completion. Validate applied
packet-filter flags before returning them to the caller. If a reply is
malformed or contradictory, or the PF reports that the VF is no longer
registered, the VF can no longer trust that its state matches the PF.
Require a new VF registration before accepting traffic again.

The protocol's ret_minor field counts non-SKIPPED per-entry result codes,
including the idempotent DUPLICATE and NOT_FOUND outcomes. SKIPPED remains
an operation-specific policy result but is not part of that aggregate
count.

Treat a short existing capability, register or unregister reply as a
protocol fault when it matches the pending transaction. A malformed PF
link-state notification can also leave state uncertain and requires
reconnect. An errno-style packet-filter error leaves no authoritative
applied mask, so reconnect rather than retaining the previous mask.

Return stable policy errors to callers while retaining retry semantics for
operations that made no state change. A coherent top-level MAC-operation
failure remains an ordinary error. Reserve reconnect for malformed or
indeterminate replies and explicit registration loss.

Return capability rejection through the reply status. Report an
unsupported capability version when the PF accepts the request but
returns a version below the minimum.

This patch adds only the VF side of these operations. Administrative-MAC
notification handling is added in patch 6. The in-tree V2 PF enable
path remains dormant because enic_driver does not yet register
.sriov_configure. A future PF activation series must implement PF-side
handling for the MAC-address and packet-filter mailbox requests, including
the VF policy checks, before wiring that callback.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h      |   9 +
 drivers/net/ethernet/cisco/enic/enic_mbox.c | 492 ++++++++++++++++++++++++++--
 drivers/net/ethernet/cisco/enic/enic_mbox.h |  82 +++++
 3 files changed, 564 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 7fddd68e3213..2fc9d721b670 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -244,6 +244,8 @@ enum enic_admin_chan_state {
 	ENIC_ADMIN_CHAN_QUARANTINED,
 };
 
+struct enic_mac_addr;
+
 /* Per-instance private data structure */
 struct enic {
 	struct net_device *netdev;
@@ -375,6 +377,13 @@ struct enic {
 	unsigned int vf_ack_count;
 	u64 mbox_expected_msg_num;
 	u8 mbox_expected_reply;
+	int mbox_reply_status;
+	u16 mbox_reply_filter_flags;
+	/* The request mutex keeps this caller-owned reply array alive until the
+	 * matching reply handler has copied all per-address result flags.
+	 */
+	struct enic_mac_addr *mbox_reply_mac_addrs;
+	u16 mbox_reply_mac_count;
 	bool mbox_initialized;
 
 	/* PF: per-VF MBOX state, allocated when SRIOV V2 is enabled */
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
index 3579d2980a24..c042cd2769dd 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c
@@ -6,6 +6,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/delay.h>
 #include <linux/completion.h>
+#include <linux/etherdevice.h>
 
 #include "vnic_dev.h"
 #include "vnic_wq.h"
@@ -397,6 +398,82 @@ static void enic_mbox_vf_request_finish(struct enic *enic)
 	mutex_unlock(&enic->vf_mbox_request_lock);
 }
 
+/* Return with mbox_state_lock held when this handler owns the reply. */
+static bool enic_mbox_vf_reply_claim(struct enic *enic, u8 reply_type,
+				     u64 msg_num, u8 *expected)
+{
+	spin_lock_bh(&enic->mbox_state_lock);
+	*expected = enic->mbox_expected_reply;
+	if (*expected == reply_type &&
+	    enic->mbox_expected_msg_num == msg_num)
+		return true;
+	spin_unlock_bh(&enic->mbox_state_lock);
+
+	return false;
+}
+
+enum enic_mbox_vf_reply_recovery {
+	ENIC_MBOX_VF_REPLY_OK,
+	ENIC_MBOX_VF_REPLY_RECONNECT,
+	ENIC_MBOX_VF_REPLY_REGISTRATION_LOST,
+};
+
+static int
+enic_mbox_vf_classify_reply(bool malformed, u16 ret_major,
+			    enum enic_mbox_vf_reply_recovery *recovery)
+{
+	*recovery = ENIC_MBOX_VF_REPLY_OK;
+	if (malformed) {
+		*recovery = ENIC_MBOX_VF_REPLY_RECONNECT;
+		return -EIO;
+	}
+	/* Some deployed peers return a negative errno in this 16-bit field.
+	 * Interpret protocol bits only when no unknown bits are present; otherwise
+	 * an errno such as -EINVAL could accidentally look like registration loss.
+	 */
+	if (!(ret_major & ~ENIC_MBOX_ERR_MASK) &&
+	    (ret_major & ENIC_MBOX_ERR_VF_NOT_REGISTERED)) {
+		*recovery = ENIC_MBOX_VF_REPLY_REGISTRATION_LOST;
+		return -ENODEV;
+	}
+	if (!(ret_major & ~ENIC_MBOX_ERR_MASK) &&
+	    (ret_major & ENIC_MBOX_ERR_MSG_NOT_SUPPORTED))
+		return -EOPNOTSUPP;
+	if (ret_major)
+		return -EIO;
+
+	return 0;
+}
+
+static void
+enic_mbox_vf_recover_reply_locked(struct enic *enic,
+				  enum enic_mbox_vf_reply_recovery recovery)
+{
+	bool registration_lost;
+
+	lockdep_assert_held(&enic->mbox_state_lock);
+
+	if (recovery != ENIC_MBOX_VF_REPLY_OK) {
+		registration_lost =
+			recovery == ENIC_MBOX_VF_REPLY_REGISTRATION_LOST;
+		enic_mbox_vf_mark_reconnect_locked(enic, registration_lost);
+	}
+}
+
+static void enic_mbox_vf_reply_complete(struct enic *enic)
+{
+	lockdep_assert_held(&enic->mbox_state_lock);
+	enic->mbox_expected_reply = 0;
+	enic->mbox_expected_msg_num = 0;
+	/* Publish completion before releasing the state lock.  A waiter that
+	 * hit the timeout boundary may otherwise see the claimed state, finish the
+	 * request, and let a new request reinitialize this completion before the
+	 * old handler signals it.
+	 */
+	complete(&enic->mbox_comp);
+	spin_unlock_bh(&enic->mbox_state_lock);
+}
+
 int enic_mbox_send_link_state(struct enic *enic, u16 vf_id, u32 link_state)
 {
 	struct enic_mbox_pf_link_state_notif_msg notif = {};
@@ -572,23 +649,21 @@ static void enic_mbox_vf_handle_reply(struct enic *enic, u8 reply_type,
 				      void *payload, u64 msg_num)
 {
 	struct enic_mbox_generic_reply *reply = payload;
+	enum enic_mbox_vf_reply_recovery recovery;
 	u16 ret_major = le16_to_cpu(reply->ret_major);
-	u64 expected_msg_num;
-	u8 expected_type;
+	u8 expected;
+	int status;
 
-	spin_lock_bh(&enic->mbox_state_lock);
-	expected_type = enic->mbox_expected_reply;
-	expected_msg_num = enic->mbox_expected_msg_num;
-	if (expected_type != reply_type || expected_msg_num != msg_num) {
-		spin_unlock_bh(&enic->mbox_state_lock);
+	status = enic_mbox_vf_classify_reply(false, ret_major, &recovery);
+	if (!enic_mbox_vf_reply_claim(enic, reply_type, msg_num, &expected)) {
 		netdev_warn(enic->netdev,
-			    "MBOX: stale reply %u/%llu (expected %u/%llu), drop\n",
+			    "MBOX: stale reply %u/%llu (expected %u), drop\n",
 			    reply_type, (unsigned long long)msg_num,
-			    expected_type, (unsigned long long)expected_msg_num);
+			    expected);
 		return;
 	}
 
-	if (!ret_major) {
+	if (!status) {
 		switch (reply_type) {
 		case ENIC_MBOX_VF_CAPABILITY_REPLY: {
 			struct enic_mbox_vf_capability_reply_msg *cap = payload;
@@ -605,16 +680,166 @@ static void enic_mbox_vf_handle_reply(struct enic *enic, u8 reply_type,
 			break;
 		}
 	}
-	enic->mbox_expected_reply = 0;
-	enic->mbox_expected_msg_num = 0;
-	complete(&enic->mbox_comp);
-	spin_unlock_bh(&enic->mbox_state_lock);
+	enic_mbox_vf_recover_reply_locked(enic, recovery);
+	WRITE_ONCE(enic->mbox_reply_status, status);
+	enic_mbox_vf_reply_complete(enic);
 
 	if (ret_major)
 		netdev_warn(enic->netdev,
 			    "MBOX: PF rejected reply type %u: %u/%u\n",
 			    reply_type, ret_major,
 			    le16_to_cpu(reply->ret_minor));
+	if (recovery != ENIC_MBOX_VF_REPLY_OK)
+		enic_mbox_vf_kick_recovery(enic);
+}
+
+static bool enic_mbox_vf_mac_reply_matches(const struct enic_mac_addr *request,
+					   const struct enic_mac_addr *reply)
+{
+	u16 request_flags = le16_to_cpu(request->flags);
+	u16 reply_flags = le16_to_cpu(reply->flags);
+	u16 idempotent_result = reply_flags &
+		(ENIC_MAC_ADDR_FLAG_DUPLICATE |
+		 ENIC_MAC_ADDR_FLAG_NOT_FOUND);
+	u16 result = reply_flags & ENIC_MAC_ADDR_FLAG_REPLY_MASK;
+	u16 expected_result;
+
+	if (!ether_addr_equal(request->addr, reply->addr) ||
+	    (request_flags & ENIC_MAC_ADDR_FLAG_REQUEST_MASK) !=
+	    (reply_flags & ENIC_MAC_ADDR_FLAG_REQUEST_MASK))
+		return false;
+	if (hweight16(result) > 1)
+		return false;
+
+	/* DUPLICATE is a successful ADD result and NOT_FOUND is a successful
+	 * DELETE result.  Neither is valid for the opposite operation, and a
+	 * reply cannot report both outcomes for one entry.
+	 */
+	expected_result = request_flags & ENIC_MAC_ADDR_FLAG_ADD ?
+		ENIC_MAC_ADDR_FLAG_DUPLICATE :
+		ENIC_MAC_ADDR_FLAG_NOT_FOUND;
+
+	return !idempotent_result || idempotent_result == expected_result;
+}
+
+static void enic_mbox_vf_handle_add_del_mac_reply(struct enic *enic,
+						  void *payload, u16 msg_len,
+						  u64 msg_num)
+{
+	struct enic_mbox_vf_add_del_mac_reply_msg *reply = payload;
+	enum enic_mbox_vf_reply_recovery recovery;
+	u16 reported_errors = 0;
+	u16 num_addrs = 0;
+	u16 ret_minor = 0;
+	u16 ret_major = 0;
+	u8 expected;
+	unsigned int i;
+	int status;
+
+	if (msg_len < sizeof(*reply)) {
+		status = enic_mbox_vf_classify_reply(true, 0, &recovery);
+	} else {
+		ret_major = le16_to_cpu(reply->reply.ret_major);
+		ret_minor = le16_to_cpu(reply->reply.ret_minor);
+		status = enic_mbox_vf_classify_reply(false, ret_major,
+						     &recovery);
+	}
+	if (status)
+		goto claim;
+
+	num_addrs = le16_to_cpu(reply->num_addrs);
+	if (!num_addrs || num_addrs > ENIC_MBOX_MAX_MAC_OPS ||
+	    struct_size(reply, mac_addr, num_addrs) > msg_len) {
+		status = enic_mbox_vf_classify_reply(true, 0, &recovery);
+		goto claim;
+	}
+
+claim:
+	if (!enic_mbox_vf_reply_claim(enic, ENIC_MBOX_VF_ADD_DEL_MAC_REPLY,
+				      msg_num, &expected))
+		return;
+	if (!status &&
+	    (num_addrs != enic->mbox_reply_mac_count ||
+	     !enic->mbox_reply_mac_addrs)) {
+		status = enic_mbox_vf_classify_reply(true, 0, &recovery);
+	} else if (!status) {
+		/* A detailed reply corresponds entry-for-entry with the request.
+		 * Validate the echoed request fields and operation-specific results
+		 * before exposing result flags to the waiting caller.
+		 */
+		for (i = 0; i < num_addrs; i++) {
+			struct enic_mac_addr *request =
+				&enic->mbox_reply_mac_addrs[i];
+			u16 flags = le16_to_cpu(reply->mac_addr[i].flags);
+
+			if (!enic_mbox_vf_mac_reply_matches(request,
+							    &reply->mac_addr[i])) {
+				status = enic_mbox_vf_classify_reply(true, 0,
+								     &recovery);
+				break;
+			}
+			if (flags & ENIC_MAC_ADDR_FLAG_INDETERMINATE_MASK) {
+				status = -EIO;
+				recovery = ENIC_MBOX_VF_REPLY_RECONNECT;
+				break;
+			}
+			if ((flags & ENIC_MAC_ADDR_FLAG_REPLY_MASK) &&
+			    !(flags & ENIC_MAC_ADDR_FLAG_SKIPPED))
+				reported_errors++;
+		}
+		if (!status && reported_errors != ret_minor)
+			status = enic_mbox_vf_classify_reply(true, 0,
+							     &recovery);
+
+		if (!status)
+			for (i = 0; i < num_addrs; i++)
+				enic->mbox_reply_mac_addrs[i].flags =
+					reply->mac_addr[i].flags;
+	}
+	/* After a malformed reply, the VF cannot trust that its state matches the
+	 * PF. VF_NOT_REGISTERED means the PF removed all VF state. Both require a
+	 * new registration; an ordinary policy rejection does not.
+	 */
+	enic_mbox_vf_recover_reply_locked(enic, recovery);
+	WRITE_ONCE(enic->mbox_reply_status, status);
+	enic_mbox_vf_reply_complete(enic);
+	if (recovery != ENIC_MBOX_VF_REPLY_OK)
+		enic_mbox_vf_kick_recovery(enic);
+}
+
+static void enic_mbox_vf_handle_set_pkt_filter_reply(struct enic *enic,
+						     void *payload, u16 msg_len,
+						     u64 msg_num)
+{
+	struct enic_mbox_vf_set_pkt_filter_reply_msg *reply = payload;
+	enum enic_mbox_vf_reply_recovery recovery;
+	u16 applied = 0;
+	u16 ret_major = 0;
+	u8 expected;
+	int status;
+
+	if (msg_len < sizeof(*reply)) {
+		status = enic_mbox_vf_classify_reply(true, 0, &recovery);
+	} else {
+		ret_major = le16_to_cpu(reply->reply.ret_major);
+		status = enic_mbox_vf_classify_reply(false, ret_major,
+						     &recovery);
+		if (status && (ret_major & ~ENIC_MBOX_ERR_MASK))
+			recovery = ENIC_MBOX_VF_REPLY_RECONNECT;
+	}
+	if (!status)
+		applied = le16_to_cpu(reply->reply.ret_minor);
+
+	if (!enic_mbox_vf_reply_claim(enic,
+				      ENIC_MBOX_VF_SET_PKT_FILTER_REPLY,
+				      msg_num, &expected))
+		return;
+	enic_mbox_vf_recover_reply_locked(enic, recovery);
+	WRITE_ONCE(enic->mbox_reply_status, status);
+	WRITE_ONCE(enic->mbox_reply_filter_flags, applied);
+	enic_mbox_vf_reply_complete(enic);
+	if (recovery != ENIC_MBOX_VF_REPLY_OK)
+		enic_mbox_vf_kick_recovery(enic);
 }
 
 static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload,
@@ -700,6 +925,34 @@ static bool enic_mbox_vf_payload_ok(struct enic *enic, u8 msg_type,
 	return true;
 }
 
+static void enic_mbox_vf_malformed_msg(struct enic *enic, u8 msg_type,
+				       u64 msg_num)
+{
+	u8 expected;
+
+	switch (msg_type) {
+	case ENIC_MBOX_PF_LINK_STATE_NOTIF:
+	case ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF:
+		enic_mbox_vf_require_reconnect(enic);
+		return;
+	case ENIC_MBOX_VF_CAPABILITY_REPLY:
+	case ENIC_MBOX_VF_REGISTER_REPLY:
+	case ENIC_MBOX_VF_UNREGISTER_REPLY:
+	case ENIC_MBOX_VF_ADD_DEL_MAC_REPLY:
+	case ENIC_MBOX_VF_SET_PKT_FILTER_REPLY:
+		break;
+	default:
+		return;
+	}
+
+	if (!enic_mbox_vf_reply_claim(enic, msg_type, msg_num, &expected))
+		return;
+	enic_mbox_vf_mark_reconnect_locked(enic, false);
+	WRITE_ONCE(enic->mbox_reply_status, -EIO);
+	enic_mbox_vf_reply_complete(enic);
+	enic_mbox_vf_kick_recovery(enic);
+}
+
 static void enic_mbox_vf_process_msg(struct enic *enic,
 				     struct enic_mbox_hdr *hdr, void *payload,
 				     u16 payload_len)
@@ -711,8 +964,10 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
 		size_t exp = sizeof(struct enic_mbox_vf_capability_reply_msg);
 
 		if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
-					     payload_len, exp))
+					     payload_len, exp)) {
+			enic_mbox_vf_malformed_msg(enic, hdr->msg_type, msg_num);
 			return;
+		}
 		enic_mbox_vf_handle_reply(enic, hdr->msg_type, payload, msg_num);
 		break;
 	}
@@ -720,8 +975,10 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
 		size_t exp = sizeof(struct enic_mbox_vf_register_reply_msg);
 
 		if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
-					     payload_len, exp))
+					     payload_len, exp)) {
+			enic_mbox_vf_malformed_msg(enic, hdr->msg_type, msg_num);
 			return;
+		}
 		enic_mbox_vf_handle_reply(enic, hdr->msg_type, payload, msg_num);
 		break;
 	}
@@ -729,8 +986,10 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
 		size_t exp = sizeof(struct enic_mbox_vf_register_reply_msg);
 
 		if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
-					     payload_len, exp))
+					     payload_len, exp)) {
+			enic_mbox_vf_malformed_msg(enic, hdr->msg_type, msg_num);
 			return;
+		}
 		enic_mbox_vf_handle_reply(enic, hdr->msg_type, payload, msg_num);
 		break;
 	}
@@ -738,11 +997,21 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
 		size_t exp = sizeof(struct enic_mbox_pf_link_state_notif_msg);
 
 		if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
-					     payload_len, exp))
+					     payload_len, exp)) {
+			enic_mbox_vf_malformed_msg(enic, hdr->msg_type, msg_num);
 			return;
+		}
 		enic_mbox_vf_handle_link_state(enic, payload, msg_num);
 		break;
 	}
+	case ENIC_MBOX_VF_ADD_DEL_MAC_REPLY:
+		enic_mbox_vf_handle_add_del_mac_reply(enic, payload,
+						      payload_len, msg_num);
+		break;
+	case ENIC_MBOX_VF_SET_PKT_FILTER_REPLY:
+		enic_mbox_vf_handle_set_pkt_filter_reply(enic, payload,
+							 payload_len, msg_num);
+		break;
 	default:
 		netdev_dbg(enic->netdev,
 			   "MBOX: VF unhandled msg type %u\n",
@@ -782,6 +1051,10 @@ static void enic_mbox_recv_handler(struct enic *enic, void *buf,
 			netdev_warn(enic->netdev,
 				    "MBOX: invalid msg_len %u (buf len %u)\n",
 				    msg_len, len);
+		if (!enic->vf_state &&
+		    le16_to_cpu(hdr->src_vnic_id) == ENIC_MBOX_DST_PF)
+			enic_mbox_vf_malformed_msg(enic, hdr->msg_type,
+						   le64_to_cpu(hdr->msg_num));
 		return;
 	}
 
@@ -812,10 +1085,12 @@ int enic_mbox_vf_capability_check(struct enic *enic)
 {
 	struct enic_mbox_vf_capability_msg req = {};
 	u32 version;
+	int status;
 	int err;
 
 	enic_mbox_vf_request_start(enic);
 	WRITE_ONCE(enic->pf_cap_version, 0);
+	WRITE_ONCE(enic->mbox_reply_status, 0);
 	req.version = cpu_to_le32(ENIC_MBOX_CAP_VERSION_1);
 
 	err = enic_mbox_vf_send_request(enic,
@@ -829,16 +1104,19 @@ int enic_mbox_vf_capability_check(struct enic *enic)
 
 	err = enic_mbox_wait_reply(enic, 3000);
 	version = READ_ONCE(enic->pf_cap_version);
+	status = READ_ONCE(enic->mbox_reply_status);
 	enic_mbox_vf_request_finish(enic);
 	if (err) {
 		netdev_warn(enic->netdev,
 			    "MBOX: no capability reply from PF\n");
 		return err;
 	}
+	if (status)
+		return status;
 
 	if (version < ENIC_MBOX_CAP_VERSION_1) {
 		netdev_warn(enic->netdev,
-			    "MBOX: PF rejected capability request or reported unsupported version %u\n",
+			    "MBOX: PF reported unsupported capability version %u\n",
 			    version);
 		return -EOPNOTSUPP;
 	}
@@ -849,10 +1127,12 @@ int enic_mbox_vf_capability_check(struct enic *enic)
 int enic_mbox_vf_register(struct enic *enic)
 {
 	bool registered;
+	int status;
 	int err;
 
 	enic_mbox_vf_request_start(enic);
 	WRITE_ONCE(enic->vf_registered, false);
+	WRITE_ONCE(enic->mbox_reply_status, 0);
 
 	err = enic_mbox_vf_send_request(enic, ENIC_MBOX_VF_REGISTER_REQUEST,
 					ENIC_MBOX_VF_REGISTER_REPLY, NULL, 0);
@@ -863,12 +1143,15 @@ int enic_mbox_vf_register(struct enic *enic)
 
 	err = enic_mbox_wait_reply(enic, 3000);
 	registered = READ_ONCE(enic->vf_registered);
+	status = READ_ONCE(enic->mbox_reply_status);
 	enic_mbox_vf_request_finish(enic);
 	if (err) {
 		netdev_warn(enic->netdev,
 			    "MBOX: VF registration with PF timed out\n");
 		return err;
 	}
+	if (status)
+		return status;
 
 	if (!registered)
 		return -ENODEV;
@@ -879,15 +1162,18 @@ int enic_mbox_vf_register(struct enic *enic)
 int enic_mbox_vf_unregister(struct enic *enic)
 {
 	bool registered;
+	int status;
 	int err;
 
 	if (!READ_ONCE(enic->vf_registered))
 		return 0;
+
 	enic_mbox_vf_request_start(enic);
 	if (!READ_ONCE(enic->vf_registered)) {
 		enic_mbox_vf_request_finish(enic);
 		return 0;
 	}
+	WRITE_ONCE(enic->mbox_reply_status, 0);
 
 	err = enic_mbox_vf_send_request(enic,
 					ENIC_MBOX_VF_UNREGISTER_REQUEST,
@@ -900,14 +1186,182 @@ int enic_mbox_vf_unregister(struct enic *enic)
 
 	err = enic_mbox_wait_reply(enic, 3000);
 	registered = READ_ONCE(enic->vf_registered);
+	status = READ_ONCE(enic->mbox_reply_status);
 	enic_mbox_vf_request_finish(enic);
 	if (err)
 		return err;
+	if (status)
+		return status;
 	if (registered)
 		return -EACCES;
 	return 0;
 }
 
+int enic_mbox_vf_add_del_macs(struct enic *enic,
+			      struct enic_mac_addr *macs, u16 num_macs)
+{
+	struct enic_mbox_vf_add_del_mac_msg *req;
+	unsigned int i;
+	int status;
+	int err;
+
+	if (!READ_ONCE(enic->vf_registered) || !enic->has_admin_channel)
+		return -ENODEV;
+	if (!num_macs || num_macs > ENIC_MBOX_MAX_MAC_OPS)
+		return -EINVAL;
+
+	req = kzalloc_flex(*req, mac_addr, num_macs);
+	if (!req)
+		return -ENOMEM;
+
+	req->num_addrs = cpu_to_le16(num_macs);
+	for (i = 0; i < num_macs; i++)
+		req->mac_addr[i] = macs[i];
+
+	enic_mbox_vf_request_start(enic);
+	if (!READ_ONCE(enic->vf_registered) || !enic->has_admin_channel) {
+		err = -ENODEV;
+	} else {
+		spin_lock_bh(&enic->mbox_state_lock);
+		enic->mbox_reply_mac_addrs = macs;
+		enic->mbox_reply_mac_count = num_macs;
+		spin_unlock_bh(&enic->mbox_state_lock);
+		WRITE_ONCE(enic->mbox_reply_status, 0);
+		err = enic_mbox_vf_send_request(enic,
+						ENIC_MBOX_VF_ADD_DEL_MAC_REQUEST,
+						ENIC_MBOX_VF_ADD_DEL_MAC_REPLY,
+						req,
+						struct_size(req, mac_addr,
+							    num_macs));
+	}
+	kfree(req);
+	if (err) {
+		spin_lock_bh(&enic->mbox_state_lock);
+		enic->mbox_reply_mac_addrs = NULL;
+		enic->mbox_reply_mac_count = 0;
+		spin_unlock_bh(&enic->mbox_state_lock);
+		enic_mbox_vf_request_abort(enic);
+		return err;
+	}
+
+	err = enic_mbox_wait_reply(enic, 3000);
+	status = READ_ONCE(enic->mbox_reply_status);
+	spin_lock_bh(&enic->mbox_state_lock);
+	enic->mbox_reply_mac_addrs = NULL;
+	enic->mbox_reply_mac_count = 0;
+	spin_unlock_bh(&enic->mbox_state_lock);
+	if (err) {
+		/* The PF may have updated its software ledger before a hardware
+		 * failure whose reply was lost. A repeated idempotent operation could
+		 * then appear converged while hardware state is stale, so replay from
+		 * a fresh registration generation.
+		 */
+		enic_mbox_vf_require_reconnect(enic);
+		enic_mbox_vf_request_finish(enic);
+		return err;
+	}
+	enic_mbox_vf_request_finish(enic);
+
+	return status;
+}
+
+int enic_mbox_vf_add_del_mac(struct enic *enic, const u8 *addr, bool add,
+			     bool station)
+{
+	struct enic_mac_addr mac = {};
+	u16 flags = 0;
+	int err;
+
+	ether_addr_copy(mac.addr, addr);
+	if (add)
+		flags |= ENIC_MAC_ADDR_FLAG_ADD;
+	if (station)
+		flags |= ENIC_MAC_ADDR_FLAG_STATION;
+	mac.flags = cpu_to_le16(flags);
+
+	err = enic_mbox_vf_add_del_macs(enic, &mac, 1);
+	if (err)
+		return err;
+	if (le16_to_cpu(mac.flags) & ENIC_MAC_ADDR_FLAG_ERROR_MASK)
+		return -EACCES;
+
+	return 0;
+}
+
+int enic_mbox_vf_set_pkt_filter(struct enic *enic, int directed,
+				int multicast, int broadcast,
+				int promisc, int allmulti, u16 *applied_flags)
+{
+	struct enic_mbox_vf_set_pkt_filter_msg req = {};
+	u16 applied;
+	u16 flags = 0;
+	u16 required;
+	int status;
+	int err;
+
+	if (!READ_ONCE(enic->vf_registered) || !enic->has_admin_channel)
+		return -ENODEV;
+
+	if (directed)
+		flags |= CMD_PFILTER_DIRECTED;
+	if (multicast)
+		flags |= CMD_PFILTER_MULTICAST;
+	if (broadcast)
+		flags |= CMD_PFILTER_BROADCAST;
+	if (promisc)
+		flags |= CMD_PFILTER_PROMISCUOUS;
+	if (allmulti)
+		flags |= CMD_PFILTER_ALL_MULTICAST;
+	req.flags = cpu_to_le16(flags);
+
+	enic_mbox_vf_request_start(enic);
+	if (!READ_ONCE(enic->vf_registered) || !enic->has_admin_channel) {
+		enic_mbox_vf_request_abort(enic);
+		return -ENODEV;
+	}
+	WRITE_ONCE(enic->mbox_reply_status, 0);
+	WRITE_ONCE(enic->mbox_reply_filter_flags, 0);
+
+	err = enic_mbox_vf_send_request(enic,
+					ENIC_MBOX_VF_SET_PKT_FILTER_REQUEST,
+					ENIC_MBOX_VF_SET_PKT_FILTER_REPLY,
+					&req, sizeof(req));
+	if (err) {
+		enic_mbox_vf_request_abort(enic);
+		return err;
+	}
+
+	err = enic_mbox_wait_reply(enic, 3000);
+	status = READ_ONCE(enic->mbox_reply_status);
+	if (!err && !status) {
+		applied = READ_ONCE(enic->mbox_reply_filter_flags);
+		/* Directed, multicast, and broadcast are not policy-gated.  The PF
+		 * may only withhold the two broad receive modes, and may add directed
+		 * reception because it is mandatory for a usable VF.
+		 */
+		required = (flags | CMD_PFILTER_DIRECTED) &
+			   ~(CMD_PFILTER_PROMISCUOUS |
+			     CMD_PFILTER_ALL_MULTICAST);
+		if ((applied & ~(flags | CMD_PFILTER_DIRECTED)) ||
+		    (applied & required) != required) {
+			netdev_warn(enic->netdev,
+				    "MBOX: invalid packet filter reply %#x for request %#x\n",
+				    applied, flags);
+			enic_mbox_vf_require_reconnect(enic);
+			status = -EIO;
+		} else if (applied_flags) {
+			*applied_flags = applied;
+		}
+	}
+	if (err)
+		enic_mbox_vf_require_reconnect(enic);
+	enic_mbox_vf_request_finish(enic);
+	if (err)
+		return err;
+
+	return status;
+}
+
 void enic_mbox_init(struct enic *enic)
 {
 	bool reinit = enic->mbox_initialized;
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.h b/drivers/net/ethernet/cisco/enic/enic_mbox.h
index 37bc41a900f4..5eca3a25671e 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.h
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.h
@@ -5,6 +5,7 @@
 #define _ENIC_MBOX_H_
 
 #include <linux/bits.h>
+#include <linux/if_ether.h>
 #include <linux/types.h>
 
 /*
@@ -22,6 +23,12 @@ enum enic_mbox_msg_type {
 	ENIC_MBOX_VF_UNREGISTER_REPLY		= 5,
 	ENIC_MBOX_PF_LINK_STATE_NOTIF		= 6,
 	ENIC_MBOX_PF_LINK_STATE_ACK		= 7,
+	ENIC_MBOX_VF_ADD_DEL_MAC_REQUEST	= 10,
+	ENIC_MBOX_VF_ADD_DEL_MAC_REPLY		= 11,
+	ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF	= 12,
+	ENIC_MBOX_PF_SET_ADMIN_MAC_ACK		= 13,
+	ENIC_MBOX_VF_SET_PKT_FILTER_REQUEST	= 14,
+	ENIC_MBOX_VF_SET_PKT_FILTER_REPLY	= 15,
 	ENIC_MBOX_MAX
 };
 
@@ -42,6 +49,9 @@ struct enic_mbox_generic_reply {
 #define ENIC_MBOX_ERR_GENERIC		BIT(0)
 #define ENIC_MBOX_ERR_VF_NOT_REGISTERED	BIT(1)
 #define ENIC_MBOX_ERR_MSG_NOT_SUPPORTED	BIT(2)
+#define ENIC_MBOX_ERR_MASK		(ENIC_MBOX_ERR_GENERIC | \
+					 ENIC_MBOX_ERR_VF_NOT_REGISTERED | \
+					 ENIC_MBOX_ERR_MSG_NOT_SUPPORTED)
 
 /* ENIC_MBOX_VF_CAPABILITY_REQUEST / _REPLY */
 #define ENIC_MBOX_CAP_VERSION_0		0
@@ -80,6 +90,71 @@ struct enic_mbox_pf_link_state_ack_msg {
 	struct enic_mbox_generic_reply ack;
 };
 
+/* ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF / _ACK */
+struct enic_mbox_pf_set_admin_mac_notif_msg {
+	u8 mac_addr[ETH_ALEN];
+	__le16 pad;
+};
+
+/* ENIC_MBOX_VF_ADD_DEL_MAC_REQUEST / _REPLY */
+#define ENIC_MAC_ADDR_FLAG_ADD		BIT(0)
+#define ENIC_MAC_ADDR_FLAG_STATION	BIT(1)
+#define ENIC_MAC_ADDR_FLAG_OVERFLOW	BIT(8)
+#define ENIC_MAC_ADDR_FLAG_DUPLICATE	BIT(9)
+#define ENIC_MAC_ADDR_FLAG_FAILED	BIT(10)
+#define ENIC_MAC_ADDR_FLAG_NOT_FOUND	BIT(11)
+#define ENIC_MAC_ADDR_FLAG_ERROR	BIT(12)
+#define ENIC_MAC_ADDR_FLAG_NOT_PERMITTED BIT(13)
+#define ENIC_MAC_ADDR_FLAG_INVALID	BIT(14)
+#define ENIC_MAC_ADDR_FLAG_SKIPPED	BIT(15)
+
+#define ENIC_MAC_ADDR_FLAG_REQUEST_MASK	GENMASK(7, 0)
+#define ENIC_MAC_ADDR_FLAG_REPLY_MASK	GENMASK(15, 8)
+#define ENIC_MAC_ADDR_FLAG_INDETERMINATE_MASK \
+	(ENIC_MAC_ADDR_FLAG_FAILED | ENIC_MAC_ADDR_FLAG_ERROR)
+#define ENIC_MAC_ADDR_FLAG_PERMANENT_MASK \
+	(ENIC_MAC_ADDR_FLAG_OVERFLOW | ENIC_MAC_ADDR_FLAG_NOT_PERMITTED | \
+	 ENIC_MAC_ADDR_FLAG_INVALID)
+#define ENIC_MAC_ADDR_FLAG_ERROR_MASK	(ENIC_MAC_ADDR_FLAG_OVERFLOW | \
+					 ENIC_MAC_ADDR_FLAG_FAILED | \
+					 ENIC_MAC_ADDR_FLAG_ERROR | \
+					 ENIC_MAC_ADDR_FLAG_NOT_PERMITTED | \
+					 ENIC_MAC_ADDR_FLAG_INVALID | \
+					 ENIC_MAC_ADDR_FLAG_SKIPPED)
+
+/* The protocol permits replacing all perfect filters and the station address
+ * in one request: one delete and one add operation for each address.
+ */
+#define ENIC_MBOX_MAX_MAC_OPS		130
+
+struct enic_mac_addr {
+	u8 addr[ETH_ALEN];
+	__le16 flags;
+};
+
+struct enic_mbox_vf_add_del_mac_msg {
+	__le16 num_addrs;
+	__le16 pad;
+	struct enic_mac_addr mac_addr[];
+};
+
+struct enic_mbox_vf_add_del_mac_reply_msg {
+	struct enic_mbox_generic_reply reply;
+	__le16 num_addrs;
+	__le16 pad;
+	struct enic_mac_addr mac_addr[];
+};
+
+/* ENIC_MBOX_VF_SET_PKT_FILTER_REQUEST / _REPLY */
+struct enic_mbox_vf_set_pkt_filter_msg {
+	__le16 flags;
+	__le16 pad;
+};
+
+struct enic_mbox_vf_set_pkt_filter_reply_msg {
+	struct enic_mbox_generic_reply reply;
+};
+
 #define ENIC_MBOX_DST_PF	0xFFFF
 
 struct enic;
@@ -95,5 +170,12 @@ void enic_mbox_vf_require_reconnect(struct enic *enic);
 int enic_mbox_vf_capability_check(struct enic *enic);
 int enic_mbox_vf_register(struct enic *enic);
 int enic_mbox_vf_unregister(struct enic *enic);
+int enic_mbox_vf_add_del_macs(struct enic *enic,
+			      struct enic_mac_addr *macs, u16 num_macs);
+int enic_mbox_vf_add_del_mac(struct enic *enic, const u8 *addr, bool add,
+			     bool station);
+int enic_mbox_vf_set_pkt_filter(struct enic *enic, int directed, int multicast,
+				int broadcast, int promisc, int allmulti,
+				u16 *applied_flags);
 
 #endif /* _ENIC_MBOX_H_ */

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH net-next v6 5/7] net: add dev_addr_set_sync() for driver address updates
  2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
                   ` (3 preceding siblings ...)
  2026-12-04 15:29 ` [PATCH net-next v6 4/7] enic: validate V2 VF configuration replies Satish Kharat
@ 2026-12-04 15:29 ` Satish Kharat
  2026-12-05 16:28   ` netdev-bot+sashiko
  2026-12-04 15:29 ` [PATCH net-next v6 6/7] enic: manage V2 VF station and administrative MAC Satish Kharat
  2026-12-04 15:29 ` [PATCH net-next v6 7/7] enic: configure V2 VF receive mode over mailbox Satish Kharat
  6 siblings, 1 reply; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

Sysfs and SIOCGIFHWADDR hold dev_addr_sem for reading while copying
the primary device address. Drivers that publish a new address in
response to firmware can bypass the write-side lock taken by the
userspace MAC setter.

Add a helper for callers that already hold RTNL. Take the semaphore
around dev_addr_set() so the primary address and its list bookkeeping
are updated through the normal path. Require callers to enter before
taking the device instance lock, and leave notification and hardware
programming to the caller.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 include/linux/netdevice.h |  2 ++
 net/core/dev_api.c        | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index b5427b953229..5f3f761e821f 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -5139,6 +5139,8 @@ static inline void dev_addr_set(struct net_device *dev, const u8 *addr)
 	__dev_addr_set(dev, addr, dev->addr_len);
 }
 
+void dev_addr_set_sync(struct net_device *dev, const u8 *addr);
+
 int dev_addr_add(struct net_device *dev, const unsigned char *addr,
 		 unsigned char addr_type);
 int dev_addr_del(struct net_device *dev, const unsigned char *addr,
diff --git a/net/core/dev_api.c b/net/core/dev_api.c
index 437947dd08ed..081e9cb063b6 100644
--- a/net/core/dev_api.c
+++ b/net/core/dev_api.c
@@ -85,6 +85,27 @@ void dev_set_group(struct net_device *dev, int new_group)
 	netdev_unlock_ops(dev);
 }
 
+/**
+ * dev_addr_set_sync() - publish a driver-selected device address
+ * @dev: device whose address is being updated
+ * @addr: new address, with dev->addr_len bytes
+ *
+ * Serialize the update with sysfs and SIOCGIFHWADDR readers.
+ * The caller holds RTNL and must hold neither dev_addr_sem nor the
+ * device instance lock.
+ */
+void dev_addr_set_sync(struct net_device *dev, const u8 *addr)
+{
+	ASSERT_RTNL();
+	lockdep_assert_not_held(&dev_addr_sem);
+	lockdep_assert_not_held(&dev->lock);
+
+	down_write(&dev_addr_sem);
+	dev_addr_set(dev, addr);
+	up_write(&dev_addr_sem);
+}
+EXPORT_SYMBOL_GPL(dev_addr_set_sync);
+
 int dev_set_mac_address_user(struct net_device *dev,
 			     struct sockaddr_storage *ss,
 			     struct netlink_ext_ack *extack)

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH net-next v6 6/7] enic: manage V2 VF station and administrative MAC
  2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
                   ` (4 preceding siblings ...)
  2026-12-04 15:29 ` [PATCH net-next v6 5/7] net: add dev_addr_set_sync() for driver address updates Satish Kharat
@ 2026-12-04 15:29 ` Satish Kharat
  2026-12-05 16:28   ` netdev-bot+sashiko
  2026-12-04 15:29 ` [PATCH net-next v6 7/7] enic: configure V2 VF receive mode over mailbox Satish Kharat
  6 siblings, 1 reply; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

Use the V2 mailbox MAC operation for the VF station address and keep that
address separate from netdev secondary-unicast synchronization. Replace a
station address with one mailbox request containing a delete followed by
an add. If the PF reports that only part of the replacement was applied,
require the VF to register again before accepting traffic.

Treat the PF administrative MAC as authoritative. Process notifications
outside receive dispatch, preserve a delegated VF-selected address,
refresh the policy after every registration, and protect VF worker
shutdown and restart against teardown and recovery. Schedule receive-mode
convergence after either administrative or user-driven station-address
changes.

Reject a VF MAC change which conflicts with a cached nonzero
administrative MAC even while the datapath is down. During registration,
repair an actual device-address mismatch even when the administrative
policy itself did not change since the previous registration.

Serialize PF-driven address publication with sysfs and ioctl readers.
Use dev_addr_set_sync() in the notification worker and for registered
policy refreshes during open and recovery. Keep the semaphore scoped to
the address update and notify after it has been released.

Preserve NET_ADDR_PERM for an initial firmware-provisioned MAC so net
core records it in perm_addr at registration. If firmware reports an
all-zero MAC at probe, generate a MAC, mark it NET_ADDR_RANDOM, and
leave perm_addr all zeros. An unchanged policy refresh preserves the
assignment type.

Align the temporary MAC buffers used by the Ethernet helpers. Apply
pending administrative policy before open registers the station address,
because the policy worker can be waiting for RTNL while open holds it.
PF policy can still change after the refresh. If the PF skips every
station DELETE and rejects the ADD as not permitted, refresh policy
and retry once if it selects a different address. Keep the existing
recovery path when a reply indicates partial application or the final
state is uncertain. Use the same bounded retry on internal reopen.

Install the station address during open and remove it during an ordinary
stop while the device is present. PCI removal detaches the device before
mailbox teardown, which excludes an ordinary station delete. Quiesce and
purge administrative-MAC work around remove-time channel teardown. At
reset and removal boundaries, use VF_UNREGISTER or fresh registration
as the protocol cleanup boundary. The PF is required to
discard VF-requested state before replying. The deployed async PF attempts
this cleanup but does not propagate every hardware-delete failure, so its
ACK is not independent hardware cleanup proof. The later PF activation
series must implement the cleanup and error-handling contract.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h       |  17 +
 drivers/net/ethernet/cisco/enic/enic_admin.c |   2 +
 drivers/net/ethernet/cisco/enic/enic_dev.c   |  11 +
 drivers/net/ethernet/cisco/enic/enic_dev.h   |   1 +
 drivers/net/ethernet/cisco/enic/enic_main.c  | 652 ++++++++++++++++++++++++++-
 drivers/net/ethernet/cisco/enic/enic_mbox.c  |  30 ++
 6 files changed, 706 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 2fc9d721b670..96813592101a 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -360,6 +360,9 @@ struct enic {
 	spinlock_t vf_link_state_lock;
 	enum enic_vf_link_state vf_link_state;
 	bool vf_link_running;
+	/* Last station address which may still be installed at the PF. */
+	u8 vf_station_addr[ETH_ALEN] __aligned(2);
+	bool vf_station_addr_valid;
 
 	/* MBOX protocol state — mbox_lock serializes admin WQ sends */
 	struct mutex mbox_lock;
@@ -375,6 +378,16 @@ struct enic {
 	struct list_head vf_ack_list;
 	struct work_struct vf_ack_work;
 	unsigned int vf_ack_count;
+	struct delayed_work vf_admin_mac_work;
+	spinlock_t vf_admin_mac_lock;	/* protects pending admin MAC */
+	u8 vf_admin_mac[ETH_ALEN];
+	u8 vf_admin_mac_random_addr[ETH_ALEN];
+	bool vf_admin_mac_pending;
+	bool vf_admin_mac_random_valid;
+	bool vf_admin_mac_work_enabled;
+	bool vf_admin_mac_recovery_attempted;
+	u32 vf_admin_mac_generation;
+	u8 vf_admin_mac_retries;
 	u64 mbox_expected_msg_num;
 	u8 mbox_expected_reply;
 	int mbox_reply_status;
@@ -508,6 +521,10 @@ static inline int enic_dma_map_check(struct enic *enic, dma_addr_t dma_addr)
 }
 
 void enic_reset_addr_lists(struct enic *enic);
+void enic_vf_admin_mac_notify(struct enic *enic, const u8 *addr);
+void enic_vf_admin_mac_quiesce(struct enic *enic);
+void enic_vf_admin_mac_rearm(struct enic *enic);
+void enic_vf_admin_mac_purge(struct enic *enic);
 int enic_sriov_enabled(struct enic *enic);
 int enic_is_valid_vf(struct enic *enic, int vf);
 int enic_is_dynamic(struct enic *enic);
diff --git a/drivers/net/ethernet/cisco/enic/enic_admin.c b/drivers/net/ethernet/cisco/enic/enic_admin.c
index 8b36dadb6463..1a027da5979a 100644
--- a/drivers/net/ethernet/cisco/enic/enic_admin.c
+++ b/drivers/net/ethernet/cisco/enic/enic_admin.c
@@ -728,6 +728,8 @@ int enic_admin_channel_close(struct enic *enic)
 	int rq_err;
 	int wq_err;
 
+	if (enic_is_sriov_vf_v2(enic))
+		enic_vf_admin_mac_quiesce(enic);
 	if (!enic->has_admin_channel)
 		return 0;
 	if (READ_ONCE(enic->admin_chan_state) == ENIC_ADMIN_CHAN_DOWN)
diff --git a/drivers/net/ethernet/cisco/enic/enic_dev.c b/drivers/net/ethernet/cisco/enic/enic_dev.c
index 7d5298e6df02..b8ebf8debdd6 100644
--- a/drivers/net/ethernet/cisco/enic/enic_dev.c
+++ b/drivers/net/ethernet/cisco/enic/enic_dev.c
@@ -32,6 +32,17 @@ int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
 	return err;
 }
 
+int enic_dev_get_mac_addr(struct enic *enic, u8 *mac_addr)
+{
+	int err;
+
+	spin_lock_bh(&enic->devcmd_lock);
+	err = vnic_dev_get_mac_addr(enic->vdev, mac_addr);
+	spin_unlock_bh(&enic->devcmd_lock);
+
+	return err;
+}
+
 int enic_dev_add_station_addr(struct enic *enic)
 {
 	int err;
diff --git a/drivers/net/ethernet/cisco/enic/enic_dev.h b/drivers/net/ethernet/cisco/enic/enic_dev.h
index eed1674ff30f..d29d57d57da8 100644
--- a/drivers/net/ethernet/cisco/enic/enic_dev.h
+++ b/drivers/net/ethernet/cisco/enic/enic_dev.h
@@ -26,6 +26,7 @@
 
 int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info);
 int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats);
+int enic_dev_get_mac_addr(struct enic *enic, u8 *mac_addr);
 int enic_dev_add_station_addr(struct enic *enic);
 int enic_dev_del_station_addr(struct enic *enic);
 int enic_dev_packet_filter(struct enic *enic, int directed, int multicast,
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index 587c340854cb..0ee2ea5b2468 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -87,6 +87,9 @@ MODULE_DEVICE_TABLE(pci, enic_id_table);
 
 #define ENIC_LARGE_PKT_THRESHOLD		1000
 #define ENIC_MAX_COALESCE_TIMERS		10
+#define ENIC_VF_ADMIN_MAC_MAX_RETRIES		4
+#define ENIC_VF_ADMIN_MAC_RETRY_MS		100
+#define ENIC_VF_ADMIN_MAC_REFRESH_RETRIES	3
 /*  Interrupt moderation table, which will be used to decide the
  *  coalescing timer values
  *  {rx_rate in Mbps, mapping percentage of the range}
@@ -1064,6 +1067,512 @@ static int enic_set_mac_addr(struct net_device *netdev, char *addr)
 	return 0;
 }
 
+static void enic_vf_station_recovery_required(struct enic *enic)
+{
+	enic_mbox_vf_require_reconnect(enic);
+}
+
+static void enic_vf_station_addr_set(struct enic *enic, const u8 *addr)
+{
+	ether_addr_copy(enic->vf_station_addr, addr);
+	enic->vf_station_addr_valid = true;
+}
+
+static int enic_vf_keep_nonstation_sync(struct net_device *netdev,
+					const u8 *addr)
+{
+	struct enic *enic = netdev_priv(netdev);
+
+	if (!ether_addr_equal(addr, enic->vf_station_addr))
+		return -ENOENT;
+	if (WARN_ON_ONCE(!enic->uc_count))
+		return 0;
+	enic->uc_count--;
+
+	return 0;
+}
+
+static void enic_vf_station_sync_reset(struct enic *enic)
+{
+	if (!enic->vf_station_addr_valid)
+		return;
+
+	/* The PF keys its MAC ledger by address. A station entry is also the
+	 * receive filter for that address and must not retain a second core
+	 * synchronization reference which could later delete the station.
+	 */
+	netif_addr_lock_bh(enic->netdev);
+	__dev_uc_unsync(enic->netdev, enic_vf_keep_nonstation_sync);
+	netif_addr_unlock_bh(enic->netdev);
+}
+
+static int enic_vf_station_addr_del(struct enic *enic)
+{
+	int err;
+
+	if (!enic->vf_station_addr_valid)
+		return 0;
+
+	err = enic_mbox_vf_add_del_mac(enic, enic->vf_station_addr,
+				       false, true);
+	if (!err) {
+		enic->vf_station_addr_valid = false;
+	} else if (READ_ONCE(enic->mbox_tx_poisoned)) {
+		enic_mbox_vf_link_state_set_running(enic, false);
+	} else if (err == -EACCES) {
+		/* A definitive rejected DELETE leaves an unrequested station
+		 * filter installed. Fresh registration is the cleanup boundary.
+		 */
+		enic_vf_station_recovery_required(enic);
+	}
+
+	return err;
+}
+
+/* End every replacement with an equal-address DEL+ADD pair. A bare ADD could
+ * report DUPLICATE for a secondary exact filter without applying the current
+ * station-address policy. If another station is tracked, delete it first in
+ * the same compound request.
+ */
+static int enic_vf_station_addr_replace(struct enic *enic, const u8 *addr,
+					bool *policy_rejected)
+{
+	struct enic_mac_addr macs[3] = {};
+	bool all_deletes_skipped = true;
+	bool deletes_converged = true;
+	u16 num_macs = 0;
+	unsigned int i;
+	u16 result;
+	int err;
+
+	if (policy_rejected)
+		*policy_rejected = false;
+
+	if (enic->vf_station_addr_valid &&
+	    !ether_addr_equal(enic->vf_station_addr, addr)) {
+		ether_addr_copy(macs[num_macs].addr, enic->vf_station_addr);
+		macs[num_macs++].flags =
+			cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
+	}
+	ether_addr_copy(macs[num_macs].addr, addr);
+	macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
+	ether_addr_copy(macs[num_macs].addr, addr);
+	macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_ADD |
+					    ENIC_MAC_ADDR_FLAG_STATION);
+
+	err = enic_mbox_vf_add_del_macs(enic, macs, num_macs);
+	if (err) {
+		if (READ_ONCE(enic->mbox_tx_poisoned))
+			enic_mbox_vf_link_state_set_running(enic, false);
+		return err;
+	}
+
+	for (i = 0; i < num_macs - 1; i++) {
+		result = le16_to_cpu(macs[i].flags) &
+			 ENIC_MAC_ADDR_FLAG_REPLY_MASK;
+		if (result != ENIC_MAC_ADDR_FLAG_SKIPPED)
+			all_deletes_skipped = false;
+		if (result && result != ENIC_MAC_ADDR_FLAG_NOT_FOUND)
+			deletes_converged = false;
+	}
+	result = le16_to_cpu(macs[num_macs - 1].flags) &
+		 ENIC_MAC_ADDR_FLAG_REPLY_MASK;
+	if (deletes_converged && !result)
+		return 0;
+
+	/* A policy-rejected ADD can be reported with all preceding DELETEs
+	 * skipped. No operation changed state in that coherent result tuple.
+	 */
+	if (all_deletes_skipped && result) {
+		if (policy_rejected)
+			*policy_rejected =
+				result == ENIC_MAC_ADDR_FLAG_NOT_PERMITTED;
+		if (result & (ENIC_MAC_ADDR_FLAG_DUPLICATE |
+			      ENIC_MAC_ADDR_FLAG_PERMANENT_MASK))
+			return -EACCES;
+		return -EIO;
+	}
+
+	/* After any other partial or contradictory result, the VF does not know
+	 * which station address the PF kept. Re-register before accepting traffic.
+	 */
+	enic_vf_station_recovery_required(enic);
+	for (i = 0; i < num_macs; i++)
+		if (le16_to_cpu(macs[i].flags) &
+		    ENIC_MAC_ADDR_FLAG_PERMANENT_MASK)
+			return -EACCES;
+
+	return -EIO;
+}
+
+static void enic_vf_admin_mac_cache_selected(struct enic *enic,
+					     const u8 *addr)
+{
+	/* A zero administrative policy delegates the operational address to
+	 * the VF. Preserve a successful user selection across reconnects.
+	 */
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	if (is_zero_ether_addr(enic->vf_admin_mac)) {
+		ether_addr_copy(enic->vf_admin_mac_random_addr, addr);
+		enic->vf_admin_mac_random_valid = true;
+	}
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+}
+
+static void enic_vf_admin_mac_work(struct work_struct *work)
+{
+	struct enic *enic = container_of(to_delayed_work(work), struct enic,
+					 vf_admin_mac_work);
+	u8 policy[ETH_ALEN] __aligned(2);
+	u8 selected[ETH_ALEN] __aligned(2);
+	unsigned long delay = 0;
+	u32 generation = 0;
+	bool changed;
+	bool mutated = false;
+	bool reschedule = false;
+	bool station_installed = false;
+	bool stale = false;
+	bool zero_policy;
+	bool pending;
+	int err = 0;
+
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	pending = enic->vf_admin_mac_pending &&
+		enic->vf_admin_mac_work_enabled;
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+	if (!pending)
+		return;
+
+	/* Teardown owns RTNL while synchronously cancelling this work. Do not
+	 * block that owner.
+	 */
+	if (!rtnl_trylock()) {
+		spin_lock_bh(&enic->vf_admin_mac_lock);
+		if (enic->vf_admin_mac_pending &&
+		    enic->vf_admin_mac_work_enabled)
+			mod_delayed_work(system_percpu_wq,
+					 &enic->vf_admin_mac_work,
+					 msecs_to_jiffies(10));
+		spin_unlock_bh(&enic->vf_admin_mac_lock);
+		return;
+	}
+
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	pending = enic->vf_admin_mac_pending &&
+		enic->vf_admin_mac_work_enabled;
+	if (pending) {
+		ether_addr_copy(policy, enic->vf_admin_mac);
+		generation = enic->vf_admin_mac_generation;
+		zero_policy = is_zero_ether_addr(policy);
+		if (zero_policy && enic->vf_admin_mac_random_valid)
+			ether_addr_copy(selected,
+					enic->vf_admin_mac_random_addr);
+	}
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+	if (!pending)
+		goto unlock;
+
+	if (zero_policy && !READ_ONCE(enic->vf_admin_mac_random_valid)) {
+		eth_random_addr(selected);
+		spin_lock_bh(&enic->vf_admin_mac_lock);
+		if (!enic->vf_admin_mac_pending ||
+		    !enic->vf_admin_mac_work_enabled ||
+		    enic->vf_admin_mac_generation != generation ||
+		    !is_zero_ether_addr(enic->vf_admin_mac)) {
+			stale = true;
+		} else if (enic->vf_admin_mac_random_valid) {
+			ether_addr_copy(selected,
+					enic->vf_admin_mac_random_addr);
+		} else {
+			ether_addr_copy(enic->vf_admin_mac_random_addr, selected);
+			enic->vf_admin_mac_random_valid = true;
+		}
+		spin_unlock_bh(&enic->vf_admin_mac_lock);
+		if (stale)
+			goto unlock;
+	} else if (!zero_policy) {
+		ether_addr_copy(selected, policy);
+	}
+
+	if (!netif_device_present(enic->netdev) ||
+	    !READ_ONCE(enic->vf_registered)) {
+		err = -EAGAIN;
+		goto unlock;
+	}
+
+	/* A nonzero notification describes a station address the PF has already
+	 * installed. Zero delegates selection to the VF, which registers the
+	 * selected random address through the policy-safe replacement request.
+	 */
+	if (!READ_ONCE(enic->datapath_open)) {
+		station_installed = !zero_policy &&
+			(!enic->vf_station_addr_valid ||
+			 ether_addr_equal(enic->vf_station_addr, selected));
+	} else if (zero_policy) {
+		mutated = true;
+		err = enic_vf_station_addr_replace(enic, selected, NULL);
+		station_installed = !err;
+	} else if (enic->vf_station_addr_valid &&
+		   !ether_addr_equal(enic->vf_station_addr, selected)) {
+		mutated = true;
+		err = enic_vf_station_addr_del(enic);
+		station_installed = !err;
+	} else {
+		station_installed = true;
+	}
+	if (err)
+		goto unlock;
+
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	if (!enic->vf_admin_mac_pending ||
+	    !enic->vf_admin_mac_work_enabled ||
+	    enic->vf_admin_mac_generation != generation) {
+		stale = true;
+		/* If policy changed while the request was running, the completed
+		 * station change may no longer match it. Record recovery while holding
+		 * vf_admin_mac_lock, which also protects VF worker shutdown. Teardown
+		 * therefore either suppresses the update or sees it first, and already
+		 * uses unregister/register to clear old state.
+		 */
+		if (mutated && enic->vf_admin_mac_work_enabled)
+			enic_vf_station_recovery_required(enic);
+	} else {
+		enic->vf_admin_mac_pending = false;
+		enic->vf_admin_mac_retries = 0;
+		enic->vf_admin_mac_recovery_attempted = false;
+		if (!zero_policy)
+			enic->vf_admin_mac_random_valid = false;
+	}
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+	if (stale)
+		goto unlock;
+
+	changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
+	enic_vf_station_sync_reset(enic);
+	if (changed)
+		dev_addr_set_sync(enic->netdev, selected);
+	if (changed || (!zero_policy &&
+			enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
+		enic->netdev->addr_assign_type = zero_policy ?
+			NET_ADDR_RANDOM : NET_ADDR_SET;
+	ether_addr_copy(enic->mac_addr, selected);
+	if (station_installed)
+		enic_vf_station_addr_set(enic, selected);
+	enic_vf_station_sync_reset(enic);
+	if (enic->netdev->reg_state == NETREG_REGISTERED) {
+		if (changed)
+			call_netdevice_notifiers(NETDEV_CHANGEADDR,
+						 enic->netdev);
+		netif_rx_mode_schedule_update(enic->netdev);
+	}
+	netdev_info(enic->netdev, "MBOX: admin MAC set to %pM\n", selected);
+
+unlock:
+	rtnl_unlock();
+
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	if (err && enic->vf_admin_mac_pending &&
+	    enic->vf_admin_mac_work_enabled &&
+	    generation == enic->vf_admin_mac_generation &&
+	    !READ_ONCE(enic->mbox_send_disabled)) {
+		if (enic->vf_admin_mac_retries <
+		    ENIC_VF_ADMIN_MAC_MAX_RETRIES) {
+			enic->vf_admin_mac_retries++;
+			reschedule = true;
+			delay = msecs_to_jiffies(ENIC_VF_ADMIN_MAC_RETRY_MS);
+		} else if (!enic->vf_admin_mac_recovery_attempted) {
+			enic->vf_admin_mac_recovery_attempted = true;
+			/* vf_admin_mac_lock also protects VF worker shutdown. */
+			enic_vf_station_recovery_required(enic);
+		}
+	}
+	if (enic->vf_admin_mac_pending &&
+	    enic->vf_admin_mac_work_enabled &&
+	    generation != enic->vf_admin_mac_generation) {
+		reschedule = true;
+		delay = 0;
+	}
+	if (enic->vf_admin_mac_pending && reschedule)
+		mod_delayed_work(system_percpu_wq,
+				 &enic->vf_admin_mac_work, delay);
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+}
+
+void enic_vf_admin_mac_notify(struct enic *enic, const u8 *addr)
+{
+	bool new_policy;
+
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	new_policy = !enic->vf_admin_mac_pending ||
+		!ether_addr_equal(enic->vf_admin_mac, addr);
+	if (new_policy) {
+		ether_addr_copy(enic->vf_admin_mac, addr);
+		if (!is_zero_ether_addr(addr))
+			enic->vf_admin_mac_random_valid = false;
+		enic->vf_admin_mac_pending = true;
+		enic->vf_admin_mac_generation++;
+		enic->vf_admin_mac_retries = 0;
+		enic->vf_admin_mac_recovery_attempted = false;
+	}
+	if (new_policy && enic->vf_admin_mac_work_enabled)
+		mod_delayed_work(system_percpu_wq,
+				 &enic->vf_admin_mac_work, 0);
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+}
+
+void enic_vf_admin_mac_quiesce(struct enic *enic)
+{
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	enic->vf_admin_mac_work_enabled = false;
+	enic->vf_admin_mac_generation++;
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+	cancel_delayed_work_sync(&enic->vf_admin_mac_work);
+}
+
+void enic_vf_admin_mac_rearm(struct enic *enic)
+{
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	enic->vf_admin_mac_work_enabled = true;
+	if (enic->vf_admin_mac_pending)
+		mod_delayed_work(system_percpu_wq,
+				 &enic->vf_admin_mac_work, 0);
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+}
+
+void enic_vf_admin_mac_purge(struct enic *enic)
+{
+	enic_vf_admin_mac_quiesce(enic);
+	spin_lock_bh(&enic->vf_admin_mac_lock);
+	enic->vf_admin_mac_pending = false;
+	enic->vf_admin_mac_random_valid = false;
+	enic->vf_admin_mac_recovery_attempted = false;
+	enic->vf_admin_mac_retries = 0;
+	enic->vf_admin_mac_generation++;
+	spin_unlock_bh(&enic->vf_admin_mac_lock);
+}
+
+/* CMD_GET_MAC_ADDR is the PF-owned policy store. Re-read it after REGISTER so
+ * a lost notification cannot leave the VF using stale administrative policy.
+ */
+static int enic_vf_admin_mac_refresh(struct enic *enic)
+{
+	u8 previous_policy[ETH_ALEN] __aligned(2);
+	u8 random_addr[ETH_ALEN] __aligned(2);
+	u8 selected[ETH_ALEN] __aligned(2);
+	u8 policy[ETH_ALEN] __aligned(2);
+	u32 generation;
+	bool apply_policy;
+	bool changed;
+	bool pending;
+	bool policy_changed;
+	bool zero_policy;
+	unsigned int attempt;
+	int err;
+
+	for (attempt = 0; attempt < ENIC_VF_ADMIN_MAC_REFRESH_RETRIES;
+	     attempt++) {
+		spin_lock_bh(&enic->vf_admin_mac_lock);
+		generation = enic->vf_admin_mac_generation;
+		pending = enic->vf_admin_mac_pending;
+		ether_addr_copy(previous_policy, enic->vf_admin_mac);
+		spin_unlock_bh(&enic->vf_admin_mac_lock);
+
+		err = enic_dev_get_mac_addr(enic, policy);
+		if (err)
+			return err;
+		if (is_multicast_ether_addr(policy))
+			return -EADDRNOTAVAIL;
+
+		zero_policy = is_zero_ether_addr(policy);
+		if (zero_policy)
+			eth_random_addr(random_addr);
+
+		spin_lock_bh(&enic->vf_admin_mac_lock);
+		if (enic->vf_admin_mac_generation != generation) {
+			spin_unlock_bh(&enic->vf_admin_mac_lock);
+			continue;
+		}
+
+		policy_changed = !ether_addr_equal(previous_policy, policy);
+		apply_policy = pending || policy_changed ||
+			!is_valid_ether_addr(enic->netdev->dev_addr) ||
+			(!zero_policy &&
+			 !ether_addr_equal(enic->netdev->dev_addr, policy));
+		if (!apply_policy) {
+			ether_addr_copy(selected, enic->netdev->dev_addr);
+			if (zero_policy) {
+				ether_addr_copy(enic->vf_admin_mac_random_addr,
+						selected);
+				enic->vf_admin_mac_random_valid = true;
+			}
+		} else if (zero_policy && enic->vf_admin_mac_random_valid) {
+			ether_addr_copy(selected,
+					enic->vf_admin_mac_random_addr);
+		} else if (zero_policy) {
+			ether_addr_copy(selected, random_addr);
+			ether_addr_copy(enic->vf_admin_mac_random_addr, selected);
+			enic->vf_admin_mac_random_valid = true;
+		} else {
+			ether_addr_copy(selected, policy);
+			enic->vf_admin_mac_random_valid = false;
+		}
+		ether_addr_copy(enic->vf_admin_mac, policy);
+		enic->vf_admin_mac_pending = false;
+		enic->vf_admin_mac_recovery_attempted = false;
+		enic->vf_admin_mac_retries = 0;
+		enic->vf_admin_mac_generation++;
+		spin_unlock_bh(&enic->vf_admin_mac_lock);
+
+		changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
+		if (changed) {
+			if (enic->netdev->reg_state == NETREG_REGISTERED)
+				dev_addr_set_sync(enic->netdev, selected);
+			else
+				eth_hw_addr_set(enic->netdev, selected);
+		}
+		if (zero_policy && changed)
+			enic->netdev->addr_assign_type = NET_ADDR_RANDOM;
+		else if (!zero_policy &&
+			 enic->netdev->reg_state == NETREG_REGISTERED &&
+			 (changed ||
+			  enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
+			enic->netdev->addr_assign_type = NET_ADDR_SET;
+		ether_addr_copy(enic->mac_addr, selected);
+		if (changed && enic->netdev->reg_state == NETREG_REGISTERED)
+			call_netdevice_notifiers(NETDEV_CHANGEADDR,
+						 enic->netdev);
+
+		return 0;
+	}
+
+	return -EAGAIN;
+}
+
+static int enic_vf_station_addr_open(struct enic *enic)
+{
+	struct net_device *netdev = enic->netdev;
+	u8 requested[ETH_ALEN] __aligned(2);
+	bool policy_rejected;
+	int err;
+
+	ether_addr_copy(requested, netdev->dev_addr);
+	err = enic_vf_station_addr_replace(enic, requested, &policy_rejected);
+	if (!policy_rejected || !READ_ONCE(enic->vf_registered) ||
+	    READ_ONCE(enic->mbox_send_disabled))
+		return err;
+
+	/* PF policy can change after the last refresh, with its notification
+	 * still in flight. A clean rejection permits one attempt at the new MAC.
+	 */
+	err = enic_vf_admin_mac_refresh(enic);
+	if (err)
+		return err;
+	if (ether_addr_equal(requested, netdev->dev_addr))
+		return -EACCES;
+
+	return enic_vf_station_addr_replace(enic, netdev->dev_addr, NULL);
+}
+
 static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
 {
 	struct enic *enic = netdev_priv(netdev);
@@ -1071,6 +1580,53 @@ static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
 	char *addr = saddr->sa_data;
 	int err;
 
+	if (enic_is_sriov_vf_v2(enic)) {
+		if (!is_valid_ether_addr(addr))
+			return -EADDRNOTAVAIL;
+
+		spin_lock_bh(&enic->vf_admin_mac_lock);
+		err = is_valid_ether_addr(enic->vf_admin_mac) &&
+		      !ether_addr_equal(enic->vf_admin_mac, addr);
+		spin_unlock_bh(&enic->vf_admin_mac_lock);
+		if (err)
+			return -EPERM;
+		if (ether_addr_equal(addr, netdev->dev_addr))
+			return 0;
+
+		if (READ_ONCE(enic->datapath_open) &&
+		    !READ_ONCE(enic->vf_registered))
+			return -ENODEV;
+
+		/* An internal reset keeps IFF_UP set while its failed reopen leaves
+		 * the datapath closed. Cache the requested address in that state; the
+		 * next successful open installs it together with the datapath.
+		 */
+		if (!READ_ONCE(enic->datapath_open)) {
+			err = enic_set_mac_addr(netdev, addr);
+			if (!err)
+				enic_vf_admin_mac_cache_selected(enic, addr);
+			return err;
+		}
+
+		/* Keep the old software address visible until the complete station
+		 * replacement proves convergence.
+		 */
+		err = enic_vf_station_addr_replace(enic, addr, NULL);
+		if (err)
+			return err;
+
+		enic_vf_station_sync_reset(enic);
+		err = enic_set_mac_addr(netdev, addr);
+		if (!err) {
+			enic_vf_station_addr_set(enic, addr);
+			enic_vf_station_sync_reset(enic);
+			enic_vf_admin_mac_cache_selected(enic, addr);
+			netif_rx_mode_schedule_update(netdev);
+		}
+
+		return err;
+	}
+
 	if (netif_running(enic->netdev)) {
 		err = enic_dev_del_station_addr(enic);
 		if (err)
@@ -1730,6 +2286,7 @@ static void enic_detach_after_recovery_failure(struct enic *enic)
 static int enic_open(struct net_device *netdev)
 {
 	struct enic *enic = netdev_priv(netdev);
+	bool vf_mac_added = false;
 	bool clear_cqs = false;
 	unsigned int i;
 	int stop_err = 0;
@@ -1830,6 +2387,40 @@ static int enic_open(struct net_device *netdev)
 	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
 		enic_dev_add_station_addr(enic);
 
+	if (enic_is_sriov_vf_v2(enic)) {
+		if (!READ_ONCE(enic->vf_registered)) {
+			netdev_err(netdev, "VF is not registered with its PF\n");
+			err = -ENODEV;
+			goto err_out_disable_wq;
+		}
+
+		/* A pending administrative-MAC change may not have reached
+		 * dev_addr yet because the refresh worker backs off while RTNL is
+		 * held.  Apply the current PF policy now so a stale station
+		 * address is not registered (the PF would reject it with -EACCES).
+		 */
+		if (READ_ONCE(enic->vf_admin_mac_pending)) {
+			err = enic_vf_admin_mac_refresh(enic);
+			if (err) {
+				netdev_err(netdev,
+					   "Failed to apply pending admin MAC before open: %d\n",
+					   err);
+				goto err_out_disable_wq;
+			}
+		}
+
+		err = enic_vf_station_addr_open(enic);
+		if (err) {
+			netdev_err(netdev,
+				   "Failed to register VF station address: %d\n",
+				   err);
+			goto err_out_disable_wq;
+		}
+		enic_vf_station_addr_set(enic, netdev->dev_addr);
+		enic_vf_station_sync_reset(enic);
+		vf_mac_added = true;
+	}
+
 	enic_set_rx_mode(netdev);
 
 	netif_tx_wake_all_queues(netdev);
@@ -1891,6 +2482,15 @@ static int enic_open(struct net_device *netdev)
 		for (i = 0; i < enic->wq_count; i++)
 			napi_disable(&enic->napi[enic_cq_wq(enic, i)]);
 	netif_tx_disable(netdev);
+err_out_disable_wq:
+	if (vf_mac_added) {
+		ret = enic_vf_station_addr_del(enic);
+		if (ret) {
+			netdev_warn(netdev,
+				    "Failed to remove VF station address during open rollback: %d\n",
+				    ret);
+		}
+	}
 	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
 		enic_dev_del_station_addr(enic);
 	for (i = 0; i < enic->wq_count; i++) {
@@ -1929,7 +2529,7 @@ static int enic_open(struct net_device *netdev)
 }
 
 /* rtnl lock is held, process context */
-static int __enic_stop(struct net_device *netdev)
+static int __enic_stop(struct net_device *netdev, bool remove_vf_station)
 {
 	struct enic *enic = netdev_priv(netdev);
 	unsigned int i;
@@ -1963,6 +2563,15 @@ static int __enic_stop(struct net_device *netdev)
 		for (i = 0; i < enic->wq_count; i++)
 			napi_disable(&enic->napi[enic_cq_wq(enic, i)]);
 	netif_tx_disable(netdev);
+	if (remove_vf_station && enic_is_sriov_vf_v2(enic) &&
+	    netif_device_present(netdev) && READ_ONCE(enic->vf_registered)) {
+		err = enic_vf_station_addr_del(enic);
+		if (err) {
+			netdev_warn(netdev,
+				    "Failed to remove VF station address: %d\n",
+				    err);
+		}
+	}
 
 	/* Detach IRQ callbacks even if a later queue disable fails. */
 	enic_unset_affinity_hint(enic);
@@ -2008,7 +2617,7 @@ static int __enic_stop(struct net_device *netdev)
 
 static int enic_stop(struct net_device *netdev)
 {
-	return __enic_stop(netdev);
+	return __enic_stop(netdev, true);
 }
 
 static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
@@ -2470,8 +3079,20 @@ static int enic_admin_chan_reopen(struct enic *enic)
 			return close_err ?: err;
 		}
 		enic_reset_addr_lists(enic);
-		/* The handshake establishes a new protocol generation.
-		 * Keep RX gated until the final open check.
+		enic->vf_station_addr_valid = false;
+		err = enic_vf_admin_mac_refresh(enic);
+		if (err) {
+			int close_err;
+
+			netdev_err(enic->netdev,
+				   "Failed to refresh VF admin MAC after reset: %d\n",
+				   err);
+			close_err = enic_admin_channel_close(enic);
+			WRITE_ONCE(enic->vf_registered, false);
+			return close_err ?: err;
+		}
+		/* Establish a new protocol generation after refreshing the MAC
+		 * policy. RX stays gated until the final open check.
 		 */
 		spin_lock_bh(&enic->mbox_state_lock);
 		if (enic->vf_mbox_fault_generation != recovery_generation ||
@@ -2490,6 +3111,7 @@ static int enic_admin_chan_reopen(struct enic *enic)
 			WRITE_ONCE(enic->vf_registered, false);
 			return close_err ?: err;
 		}
+		enic_vf_admin_mac_rearm(enic);
 	} else {
 		/* The link came back up during enic_open() above while MBOX
 		 * sends were still disabled (channel not yet reopened), so that
@@ -2590,7 +3212,7 @@ static void enic_reset(struct work_struct *work)
 			WRITE_ONCE(enic->vf_registered, false);
 	}
 	if (READ_ONCE(enic->datapath_open))
-		stop_err = __enic_stop(enic->netdev);
+		stop_err = __enic_stop(enic->netdev, false);
 
 	if (enic_is_sriov_vf_v2(enic))
 		enic_mbox_vf_link_state_reset(enic);
@@ -2731,7 +3353,7 @@ static void enic_hang_reset(struct enic *enic, bool mailbox_recovery)
 			WRITE_ONCE(enic->vf_registered, false);
 	}
 	if (READ_ONCE(enic->datapath_open))
-		stop_err = __enic_stop(enic->netdev);
+		stop_err = __enic_stop(enic->netdev, false);
 	if (enic_is_sriov_vf_v2(enic))
 		enic_mbox_vf_link_state_reset(enic);
 	if (stop_err || enic_control_dma_unresolved(enic)) {
@@ -3679,6 +4301,9 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 * cancel_work_sync()) would otherwise act on an uninitialised work.
 	 */
 	INIT_WORK(&enic->link_notify_work, enic_link_notify_work_handler);
+	spin_lock_init(&enic->vf_admin_mac_lock);
+	INIT_DELAYED_WORK(&enic->vf_admin_mac_work,
+			  enic_vf_admin_mac_work);
 
 	/* V2 VF: open admin channel and register with PF.
 	 * Must happen before register_netdev so the VF is fully
@@ -3710,6 +4335,12 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		}
 		dev_info(dev, "V2 VF registered, VF index %u\n",
 			 READ_ONCE(enic->vf_id));
+		err = enic_vf_admin_mac_refresh(enic);
+		if (err) {
+			dev_err(dev,
+				"MBOX VF admin MAC refresh failed: %d\n", err);
+			goto err_out_admin_close;
+		}
 	}
 
 	netif_set_real_num_tx_queues(netdev, enic->wq_count);
@@ -3836,6 +4467,8 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		dev_err(dev, "Cannot register net device, aborting\n");
 		goto err_out_admin_close;
 	}
+	if (enic_is_sriov_vf_v2(enic))
+		enic_vf_admin_mac_rearm(enic);
 
 	return 0;
 
@@ -3908,9 +4541,12 @@ static void enic_remove(struct pci_dev *pdev)
 
 		/* Close the admin channel and unregister from the PF before
 		 * unregister_netdev() to prevent a late PF notification from
-		 * touching a netdev that is being torn down.
+		 * touching a netdev that is being torn down. VF_UNREGISTER is the
+		 * protocol teardown operation: the PF removes all VF-requested
+		 * configuration, including the station address, before replying.
 		 */
 		if (enic_is_sriov_vf_v2(enic)) {
+			enic_vf_admin_mac_quiesce(enic);
 			if (READ_ONCE(enic->vf_registered)) {
 				int unreg_err = enic_mbox_vf_unregister(enic);
 
@@ -3929,6 +4565,8 @@ static void enic_remove(struct pci_dev *pdev)
 		 * enic_link_check() scheduled it just as SR-IOV was disabled.
 		 */
 		cancel_work_sync(&enic->link_notify_work);
+		if (enic_is_sriov_vf_v2(enic))
+			enic_vf_admin_mac_purge(enic);
 #ifdef CONFIG_PCI_IOV
 		if (enic_sriov_enabled(enic)) {
 			if (enic->vf_type == ENIC_VF_TYPE_V2)
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
index c042cd2769dd..85d0152cda6e 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c
@@ -880,6 +880,25 @@ static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload,
 			       ret_major);
 }
 
+static void enic_mbox_vf_handle_admin_mac(struct enic *enic, void *payload,
+					  u64 msg_num)
+{
+	struct enic_mbox_pf_set_admin_mac_notif_msg *notif = payload;
+	u16 ret_major = 0;
+
+	if (is_multicast_ether_addr(notif->mac_addr)) {
+		netdev_warn(enic->netdev,
+			    "MBOX: rejecting multicast admin MAC %pM\n",
+			    notif->mac_addr);
+		ret_major = ENIC_MBOX_ERR_GENERIC;
+	} else {
+		enic_vf_admin_mac_notify(enic, notif->mac_addr);
+	}
+
+	enic_mbox_vf_queue_ack(enic, ENIC_MBOX_PF_SET_ADMIN_MAC_ACK,
+			       msg_num, ret_major);
+}
+
 void enic_mbox_vf_link_state_reset(struct enic *enic)
 {
 	spin_lock_bh(&enic->vf_link_state_lock);
@@ -1004,6 +1023,17 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
 		enic_mbox_vf_handle_link_state(enic, payload, msg_num);
 		break;
 	}
+	case ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF: {
+		size_t exp = sizeof(struct enic_mbox_pf_set_admin_mac_notif_msg);
+
+		if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
+					     payload_len, exp)) {
+			enic_mbox_vf_malformed_msg(enic, hdr->msg_type, msg_num);
+			return;
+		}
+		enic_mbox_vf_handle_admin_mac(enic, payload, msg_num);
+		break;
+	}
 	case ENIC_MBOX_VF_ADD_DEL_MAC_REPLY:
 		enic_mbox_vf_handle_add_del_mac_reply(enic, payload,
 						      payload_len, msg_num);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH net-next v6 7/7] enic: configure V2 VF receive mode over mailbox
  2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
                   ` (5 preceding siblings ...)
  2026-12-04 15:29 ` [PATCH net-next v6 6/7] enic: manage V2 VF station and administrative MAC Satish Kharat
@ 2026-12-04 15:29 ` Satish Kharat
  2026-12-05 16:28   ` netdev-bot+sashiko
  6 siblings, 1 reply; 13+ messages in thread
From: Satish Kharat @ 2026-12-04 15:29 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn
  Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
	Reese Faucette, Satish Kharat, Stanislav Fomichev

V2 VFs cannot program receive filters directly. Add an asynchronous
receive-mode callback that sends unicast and multicast address changes and
packet-filter settings through the VF's one-request-at-a-time mailbox
path.

Complete all phases required for one address-list snapshot before
reporting success from the callback. Retryable errors request the bounded
netdev-core retry path rather than claiming convergence. Process every
stale delete before new adds and reserve capacity for 31 secondary unicast
and 32 multicast entries, because deployed async PFs count the station
address in the same 32-entry unicast table. Install that finite exact-
filter subset even when broad coverage is required or denied, leaving
overflow entries unsynchronized for later convergence.

Use only validated applied packet-filter state when ordering broad-mode
transitions. Enable newly required broad coverage before exact-filter work
and withdraw stale broad coverage before installing its finite
replacement. If a combined transition cannot establish the new broad mode
while an old one must be withdrawn, reconnect so stale acceptance cannot
survive. Log refused broad modes at debug level during open and runtime
updates. Coverage depends on the applied mask reported by the PF.

Track detailed per-address results so idempotent outcomes converge and
stable policy denials alone do not consume the retry budget. Supported PFs
reject whole requests before applying operations and report individual
operation failures separately. Require fresh registration after a request-
wide -EIO involving DELETE, retiring stale filters from the previous
snapshot. Keep local pre-submit and add-only rejections on the normal
retry path. Keep the station address out of both secondary address lists.

Exclude an all-zero MAC from requested counts and operation collection
before projecting exact-filter occupancy. The PF rejects that address as
INVALID, so reserving capacity for it would crowd out a later valid
address on every update.

Require the individual/group bit to match the netdev address-list class
before counting an address or collecting its operations. The PF tracks
a single filter per raw MAC. Counting the same MAC in both lists can
reserve capacity twice and removing one reference can delete the filter
while the other list still considers it synchronized.

Select the asynchronous netdev operations only for V2 VFs. A failed
internal reopen can leave IFF_UP and VF registration set while the
datapath is closed. Skip that callback without spending its retry
budget. Replay receive mode after a successful internal reopen.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/net/ethernet/cisco/enic/enic.h      |   3 +
 drivers/net/ethernet/cisco/enic/enic_main.c | 499 +++++++++++++++++++++++++++-
 2 files changed, 490 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 96813592101a..feece70330be 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -397,6 +397,9 @@ struct enic {
 	 */
 	struct enic_mac_addr *mbox_reply_mac_addrs;
 	u16 mbox_reply_mac_count;
+	u16 vf_pkt_filter_requested;
+	u16 vf_pkt_filter_applied;
+	bool vf_pkt_filter_valid;
 	bool mbox_initialized;
 
 	/* PF: per-VF MBOX state, allocated when SRIOV V2 is enabled */
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index 0ee2ea5b2468..116666be6034 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1048,6 +1048,8 @@ void enic_reset_addr_lists(struct enic *enic)
 	enic->uc_count = 0;
 	enic->flags = 0;
 	netif_addr_unlock_bh(netdev);
+
+	enic->vf_pkt_filter_valid = false;
 }
 
 static int enic_set_mac_addr(struct net_device *netdev, char *addr)
@@ -1664,17 +1666,425 @@ static int enic_set_mac_address(struct net_device *netdev, void *p)
 	return enic_dev_add_station_addr(enic);
 }
 
+static u16 enic_rx_mode_to_pkt_filter(struct net_device *netdev,
+				      unsigned int uc_count,
+				      unsigned int mc_count)
+{
+	u16 flags = CMD_PFILTER_DIRECTED;
+
+	if (netdev->flags & IFF_MULTICAST)
+		flags |= CMD_PFILTER_MULTICAST;
+	if (netdev->flags & IFF_BROADCAST)
+		flags |= CMD_PFILTER_BROADCAST;
+	if ((netdev->flags & IFF_PROMISC) ||
+	    uc_count > ENIC_UNICAST_PERFECT_FILTERS)
+		flags |= CMD_PFILTER_PROMISCUOUS;
+	if ((netdev->flags & IFF_ALLMULTI) ||
+	    mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
+		flags |= CMD_PFILTER_ALL_MULTICAST;
+
+	return flags;
+}
+
+/* Deployed async PFs count the station MAC in the 32-entry UC table. */
+static bool enic_vf_uc_needs_promisc(unsigned int uc_count)
+{
+	return uc_count > ENIC_UNICAST_PERFECT_FILTERS - 1;
+}
+
+static int enic_vf_set_pkt_filter(struct enic *enic, u16 flags,
+				  u16 *applied_flags)
+{
+	u16 applied;
+	int err;
+
+	/* The PF can change trust policy independently and thereby withdraw
+	 * broad modes. Always refresh those requests so the returned applied
+	 * flags remain authoritative. The other modes are not trust-gated and
+	 * can be reused for ordinary address-list churn.
+	 */
+	if (!(flags & (CMD_PFILTER_PROMISCUOUS |
+		       CMD_PFILTER_ALL_MULTICAST)) &&
+	    enic->vf_pkt_filter_valid &&
+	    enic->vf_pkt_filter_requested == flags) {
+		if (applied_flags)
+			*applied_flags = enic->vf_pkt_filter_applied;
+		return 0;
+	}
+
+	err = enic_mbox_vf_set_pkt_filter(enic,
+					  !!(flags & CMD_PFILTER_DIRECTED),
+					  !!(flags & CMD_PFILTER_MULTICAST),
+					  !!(flags & CMD_PFILTER_BROADCAST),
+					  !!(flags & CMD_PFILTER_PROMISCUOUS),
+					  !!(flags & CMD_PFILTER_ALL_MULTICAST),
+					  &applied);
+	if (err)
+		return err;
+
+	enic->vf_pkt_filter_requested = flags;
+	enic->vf_pkt_filter_applied = applied;
+	enic->vf_pkt_filter_valid = true;
+	if (applied_flags)
+		*applied_flags = applied;
+
+	return 0;
+}
+
+static void enic_vf_report_pkt_filter_denial(struct net_device *netdev,
+					     u16 requested, u16 applied)
+{
+	if ((requested & CMD_PFILTER_PROMISCUOUS) &&
+	    !(applied & CMD_PFILTER_PROMISCUOUS))
+		netdev_dbg(netdev, "PF policy denied promiscuous receive mode\n");
+	if ((requested & CMD_PFILTER_ALL_MULTICAST) &&
+	    !(applied & CMD_PFILTER_ALL_MULTICAST))
+		netdev_dbg(netdev,
+			   "PF policy denied all-multicast receive mode\n");
+}
+
+struct enic_vf_mac_op {
+	struct netdev_hw_addr *ha;
+	unsigned int *filter_count;
+};
+
+static bool
+enic_vf_secondary_addr_valid(const struct enic *enic,
+			     const struct netdev_hw_addr *ha)
+{
+	u8 type = is_multicast_ether_addr(ha->addr) ?
+		  NETDEV_HW_ADDR_T_MULTICAST : NETDEV_HW_ADDR_T_UNICAST;
+
+	/* The PF stores one exact filter per MAC. Admit it from the list
+	 * matching its Ethernet address class, and leave the station separate.
+	 */
+	return ha->type == type && !is_zero_ether_addr(ha->addr) &&
+	       !(enic->vf_station_addr_valid &&
+		 ether_addr_equal(ha->addr, enic->vf_station_addr));
+}
+
+static unsigned int
+enic_vf_addr_list_count(const struct enic *enic,
+			const struct netdev_hw_addr_list *list)
+{
+	const struct netdev_hw_addr *ha;
+	unsigned int count = 0;
+
+	netdev_hw_addr_list_for_each(ha, list)
+		if (ha->refcount > ha->sync_cnt &&
+		    enic_vf_secondary_addr_valid(enic, ha))
+			count++;
+
+	return count;
+}
+
+static int enic_vf_collect_mac_ops(struct enic *enic,
+				   struct netdev_hw_addr_list *list,
+				   bool add,
+				   unsigned int *filter_count,
+				   unsigned int *projected_count,
+				   unsigned int max_filters,
+				   struct enic_mac_addr *macs,
+				   struct enic_vf_mac_op *ops,
+				   u16 *num_ops)
+{
+	struct netdev_hw_addr *ha;
+	u16 pos = *num_ops;
+
+	netdev_hw_addr_list_for_each(ha, list) {
+		if (!enic_vf_secondary_addr_valid(enic, ha))
+			continue;
+		if (add) {
+			if (ha->sync_cnt || *projected_count >= max_filters)
+				continue;
+		} else {
+			if (!ha->sync_cnt || ha->refcount != ha->sync_cnt)
+				continue;
+			WARN_ON_ONCE(!*projected_count);
+		}
+		if (pos == ENIC_MBOX_MAX_MAC_OPS)
+			return -E2BIG;
+
+		ether_addr_copy(macs[pos].addr, ha->addr);
+		macs[pos].flags = add ?
+			cpu_to_le16(ENIC_MAC_ADDR_FLAG_ADD) : 0;
+		ops[pos].ha = ha;
+		ops[pos].filter_count = filter_count;
+		pos++;
+		if (add)
+			(*projected_count)++;
+		else if (*projected_count)
+			(*projected_count)--;
+	}
+
+	*num_ops = pos;
+	return 0;
+}
+
+static int enic_vf_sync_mac_filters(struct enic *enic,
+				    struct netdev_hw_addr_list *uc,
+				    struct netdev_hw_addr_list *mc)
+{
+	unsigned int projected_mc = enic->mc_count;
+	unsigned int projected_uc = enic->uc_count;
+	struct enic_vf_mac_op *ops;
+	struct enic_mac_addr *macs;
+	bool permanent_add = false;
+	bool retryable_add = false;
+	bool has_delete = false;
+	bool reconnect = false;
+	u16 num_ops = 0;
+	unsigned int i;
+	int err = 0;
+
+	/* A class can contribute at most its installed perfect filters as
+	 * deletes and its finite perfect-filter limit as adds. Keep the wire
+	 * batch large enough for both classes so an update always fits in one
+	 * transaction and -E2BIG remains only a defensive state-corruption
+	 * check.
+	 */
+	BUILD_BUG_ON(ENIC_MBOX_MAX_MAC_OPS <
+		     2 * (ENIC_UNICAST_PERFECT_FILTERS - 1 +
+			  ENIC_MULTICAST_PERFECT_FILTERS));
+
+	macs = kcalloc(ENIC_MBOX_MAX_MAC_OPS, sizeof(*macs), GFP_KERNEL);
+	if (!macs)
+		return -ENOMEM;
+	ops = kcalloc(ENIC_MBOX_MAX_MAC_OPS, sizeof(*ops), GFP_KERNEL);
+	if (!ops) {
+		err = -ENOMEM;
+		goto free_macs;
+	}
+
+	/* Collect all stale deletes before any add. Projected occupancy reserves
+	 * only replies which could fit after those deletes; actual counts change
+	 * below only for successful per-operation results.
+	 */
+	err = enic_vf_collect_mac_ops(enic, uc, false, &enic->uc_count,
+				      &projected_uc, 0,
+				      macs, ops, &num_ops);
+	if (err)
+		goto free_ops;
+	err = enic_vf_collect_mac_ops(enic, mc, false, &enic->mc_count,
+				      &projected_mc, 0,
+				      macs, ops, &num_ops);
+	if (err)
+		goto free_ops;
+	has_delete = num_ops != 0;
+
+	err = enic_vf_collect_mac_ops(enic, uc, true, &enic->uc_count,
+				      &projected_uc,
+				      ENIC_UNICAST_PERFECT_FILTERS - 1,
+				      macs, ops, &num_ops);
+	if (err)
+		goto free_ops;
+	err = enic_vf_collect_mac_ops(enic, mc, true, &enic->mc_count,
+				      &projected_mc,
+				      ENIC_MULTICAST_PERFECT_FILTERS,
+				      macs, ops, &num_ops);
+	if (err || !num_ops)
+		goto free_ops;
+
+	/* Keep exact-filter operations in one MAC request. Packet-filter mode
+	 * transitions may issue separate requests in the same callback.
+	 */
+	err = enic_mbox_vf_add_del_macs(enic, macs, num_ops);
+	if (err) {
+		/* Supported PFs reject a whole request before applying operations.
+		 * A rejected DELETE batch leaves stale acceptance from the previous
+		 * snapshot. Fresh registration retires it; ADD-only rejections retry.
+		 */
+		if (err == -EIO && has_delete &&
+		    !READ_ONCE(enic->mbox_tx_poisoned) &&
+		    !READ_ONCE(enic->vf_mbox_reconnect_required))
+			enic_mbox_vf_require_reconnect(enic);
+		goto free_ops;
+	}
+
+	for (i = 0; i < num_ops; i++) {
+		u16 flags = le16_to_cpu(macs[i].flags);
+		bool add = flags & ENIC_MAC_ADDR_FLAG_ADD;
+
+		if (flags & ENIC_MAC_ADDR_FLAG_SKIPPED) {
+			if (add)
+				retryable_add = true;
+			else
+				reconnect = true;
+			continue;
+		}
+		if (flags & ENIC_MAC_ADDR_FLAG_PERMANENT_MASK) {
+			if (add)
+				permanent_add = true;
+			else
+				reconnect = true;
+			continue;
+		}
+
+		if (add) {
+			ops[i].ha->sync_cnt++;
+			ops[i].ha->refcount++;
+			(*ops[i].filter_count)++;
+		} else {
+			ops[i].ha->sync_cnt--;
+			ops[i].ha->refcount--;
+			if (WARN_ON_ONCE(!*ops[i].filter_count))
+				err = -EIO;
+			else
+				(*ops[i].filter_count)--;
+		}
+	}
+
+	/* A failed DELETE can leave hardware accepting an address no longer in
+	 * the requested list.  Registration is the fail-closed cleanup boundary.
+	 * A skipped ADD changes no acceptance state and can use the bounded core
+	 * retry path.  Permanent ADD denials remain stable policy results.
+	 */
+	if (reconnect) {
+		enic_mbox_vf_require_reconnect(enic);
+		err = -EIO;
+	} else if (err != -EIO) {
+		/* Do not let a retryable or permanently-denied ADD overwrite an
+		 * installed-filter counter inconsistency (-EIO) detected above.
+		 */
+		if (retryable_add)
+			err = -EAGAIN;
+		else if (permanent_add)
+			err = -EACCES;
+	}
+
+free_ops:
+	kfree(ops);
+free_macs:
+	kfree(macs);
+	return err;
+}
+
+static int enic_set_vf_rx_mode(struct net_device *netdev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc)
+{
+	struct enic *enic = netdev_priv(netdev);
+	unsigned int uc_count = enic_vf_addr_list_count(enic, uc);
+	unsigned int mc_count = enic_vf_addr_list_count(enic, mc);
+	u16 flags = enic_rx_mode_to_pkt_filter(netdev, uc_count, mc_count);
+	bool uc_overflow = enic_vf_uc_needs_promisc(uc_count);
+	u16 broad_modes = CMD_PFILTER_PROMISCUOUS |
+			  CMD_PFILTER_ALL_MULTICAST;
+	bool target_filter_updated = false;
+	bool broad_enable_needed;
+	bool broad_withdrawal;
+	u16 prefilter_flags;
+	bool filter_needed;
+	u16 applied_broad;
+	u16 applied_flags;
+	int err;
+
+	/* IFF_UP can survive a failed internal reopen. The next successful
+	 * open will replay receive mode after the datapath is ready.
+	 */
+	if (!READ_ONCE(enic->datapath_open))
+		return 0;
+
+	if (uc_overflow)
+		flags |= CMD_PFILTER_PROMISCUOUS;
+
+	if (!READ_ONCE(enic->vf_registered))
+		return -ENODEV;
+
+	filter_needed = !enic->vf_pkt_filter_valid ||
+			 enic->vf_pkt_filter_requested != flags ||
+			 (flags & broad_modes);
+	applied_broad = enic->vf_pkt_filter_valid ?
+		enic->vf_pkt_filter_applied & broad_modes : 0;
+	broad_enable_needed = flags & broad_modes & ~applied_broad;
+	broad_withdrawal = applied_broad & ~flags;
+	if (broad_enable_needed) {
+		/* Establish newly required broad coverage before an independent
+		 * exact-address rejection can block it. Retain currently applied
+		 * broad modes while establishing the newly required modes.
+		 */
+		prefilter_flags = flags;
+		prefilter_flags |= applied_broad;
+		err = enic_vf_set_pkt_filter(enic, prefilter_flags,
+					     &applied_flags);
+		if (err) {
+			/* A combined transition retains the old applied broad mode
+			 * until the new one is established. If that request fails, the
+			 * stale mode may remain active outside the requested policy.
+			 */
+			if (broad_withdrawal &&
+			    !READ_ONCE(enic->mbox_tx_poisoned) &&
+			    !READ_ONCE(enic->vf_mbox_reconnect_required))
+				enic_mbox_vf_require_reconnect(enic);
+			return err;
+		}
+		target_filter_updated = prefilter_flags == flags;
+		enic_vf_report_pkt_filter_denial(netdev, flags, applied_flags);
+	}
+
+	if (broad_withdrawal) {
+		/* Withdraw stale broad acceptance before installing its finite
+		 * replacement. Complete both phases in this callback so a synchronous
+		 * receive-mode operation cannot return between them.
+		 */
+		err = enic_vf_set_pkt_filter(enic, flags, &applied_flags);
+		if (err) {
+			/* The previously applied broad mode may still be active.  Do
+			 * not rely on the core's bounded retry budget to narrow it.
+			 * Fresh registration is the fail-closed policy boundary.  A
+			 * local send timeout is already terminal and cannot use ordinary
+			 * reconnect recovery.
+			 */
+			if (!READ_ONCE(enic->mbox_tx_poisoned) &&
+			    !READ_ONCE(enic->vf_mbox_reconnect_required))
+				enic_mbox_vf_require_reconnect(enic);
+			return err;
+		}
+		target_filter_updated = true;
+		enic_vf_report_pkt_filter_denial(netdev, flags, applied_flags);
+	}
+
+	/* Install and retain the finite exact-filter subset even for an
+	 * overflowing class. Broad mode covers the remaining addresses when PF
+	 * policy permits it. Deletes are applied first so later updates can fill
+	 * newly available exact-filter slots.
+	 */
+	err = enic_vf_sync_mac_filters(enic, uc, mc);
+	if (err == -EACCES) {
+		/* Do not spend the core retry budget repeating an exact operation
+		 * that the PF rejected permanently. Finish any independent packet
+		 * policy change below before returning success.
+		 */
+		err = 0;
+	}
+	if (err)
+		return err;
+
+	if (!target_filter_updated && filter_needed) {
+		err = enic_vf_set_pkt_filter(enic, flags, &applied_flags);
+		if (err)
+			return err;
+	} else if (!target_filter_updated) {
+		applied_flags = enic->vf_pkt_filter_applied;
+	}
+
+	enic_vf_report_pkt_filter_denial(netdev, flags, applied_flags);
+
+	return 0;
+}
+
 /* netif_tx_lock held, BHs disabled */
 static void enic_set_rx_mode(struct net_device *netdev)
 {
 	struct enic *enic = netdev_priv(netdev);
-	int directed = 1;
-	int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
-	int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
-	int promisc = (netdev->flags & IFF_PROMISC) ||
-		netdev_uc_count(netdev) > ENIC_UNICAST_PERFECT_FILTERS;
-	int allmulti = (netdev->flags & IFF_ALLMULTI) ||
-		netdev_mc_count(netdev) > ENIC_MULTICAST_PERFECT_FILTERS;
+	u16 filter_flags = enic_rx_mode_to_pkt_filter(netdev,
+					       netdev_uc_count(netdev),
+					       netdev_mc_count(netdev));
+	int directed = !!(filter_flags & CMD_PFILTER_DIRECTED);
+	int multicast = !!(filter_flags & CMD_PFILTER_MULTICAST);
+	int broadcast = !!(filter_flags & CMD_PFILTER_BROADCAST);
+	int promisc = !!(filter_flags & CMD_PFILTER_PROMISCUOUS);
+	int allmulti = !!(filter_flags & CMD_PFILTER_ALL_MULTICAST);
 	unsigned int flags = netdev->flags |
 		(allmulti ? IFF_ALLMULTI : 0) |
 		(promisc ? IFF_PROMISC : 0);
@@ -2287,9 +2697,13 @@ static int enic_open(struct net_device *netdev)
 {
 	struct enic *enic = netdev_priv(netdev);
 	bool vf_mac_added = false;
+	unsigned int vf_mc_count;
+	unsigned int vf_uc_count;
 	bool clear_cqs = false;
-	unsigned int i;
+	u16 vf_filter_applied;
+	u16 vf_filter_flags;
 	int stop_err = 0;
+	unsigned int i;
 	int err, ret;
 	unsigned int max_pkt_len = netdev->mtu + VLAN_ETH_HLEN;
 	struct page_pool_params pp_params = {
@@ -2386,7 +2800,6 @@ static int enic_open(struct net_device *netdev)
 
 	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
 		enic_dev_add_station_addr(enic);
-
 	if (enic_is_sriov_vf_v2(enic)) {
 		if (!READ_ONCE(enic->vf_registered)) {
 			netdev_err(netdev, "VF is not registered with its PF\n");
@@ -2419,9 +2832,31 @@ static int enic_open(struct net_device *netdev)
 		enic_vf_station_addr_set(enic, netdev->dev_addr);
 		enic_vf_station_sync_reset(enic);
 		vf_mac_added = true;
+
+		netif_addr_lock_bh(netdev);
+		vf_uc_count = enic_vf_addr_list_count(enic, &netdev->uc);
+		vf_mc_count = enic_vf_addr_list_count(enic, &netdev->mc);
+		netif_addr_unlock_bh(netdev);
+
+		vf_filter_flags = enic_rx_mode_to_pkt_filter(netdev,
+							     vf_uc_count,
+							     vf_mc_count);
+		if (enic_vf_uc_needs_promisc(vf_uc_count))
+			vf_filter_flags |= CMD_PFILTER_PROMISCUOUS;
+		err = enic_vf_set_pkt_filter(enic, vf_filter_flags,
+					     &vf_filter_applied);
+		if (err) {
+			netdev_err(netdev,
+				   "Failed to configure VF packet filter: %d\n",
+				   err);
+			goto err_out_disable_wq;
+		}
+		enic_vf_report_pkt_filter_denial(netdev, vf_filter_flags,
+						 vf_filter_applied);
 	}
 
-	enic_set_rx_mode(netdev);
+	if (!enic_is_sriov_vf_v2(enic))
+		enic_set_rx_mode(netdev);
 
 	netif_tx_wake_all_queues(netdev);
 
@@ -2622,6 +3057,7 @@ static int enic_stop(struct net_device *netdev)
 
 static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
 {
+	struct enic *enic = netdev_priv(netdev);
 	bool running = netif_running(netdev);
 	int err = 0;
 
@@ -2638,6 +3074,8 @@ static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
 		err = enic_open(netdev);
 		if (err)
 			return err;
+		if (enic_is_sriov_vf_v2(enic))
+			netif_rx_mode_schedule_update(netdev);
 	}
 
 	return 0;
@@ -3273,6 +3711,12 @@ static void enic_reset(struct work_struct *work)
 		netdev_err(enic->netdev,
 			   "Failed to reopen datapath after reset: %d\n", err);
 		goto reset_out;
+	} else if (reopen && enic_is_sriov_vf_v2(enic)) {
+		/* Internal reset bypasses __dev_open(), which normally schedules the
+		 * asynchronous receive-mode upload after ndo_open. Schedule an update
+		 * after enic_reset_addr_lists() marked the lists unsynchronized.
+		 */
+		netif_rx_mode_schedule_update(enic->netdev);
 	}
 
 	/* A PF reopens its admin channel after the datapath and re-pushes link
@@ -3410,6 +3854,8 @@ static void enic_hang_reset(struct enic *enic, bool mailbox_recovery)
 		netdev_err(enic->netdev,
 			   "Failed to reopen datapath after hang reset: %d\n", err);
 		goto hang_reset_out;
+	} else if (reopen && enic_is_sriov_vf_v2(enic)) {
+		netif_rx_mode_schedule_update(enic->netdev);
 	}
 
 	/* A PF reopens its admin channel after the datapath and re-pushes link
@@ -3693,6 +4139,30 @@ static const struct net_device_ops enic_netdev_dynamic_ops = {
 	.ndo_features_check	= enic_features_check,
 };
 
+static const struct net_device_ops enic_netdev_vf_v2_ops = {
+	.ndo_open		= enic_open,
+	.ndo_stop		= enic_stop,
+	.ndo_start_xmit		= enic_hard_start_xmit,
+	.ndo_get_stats64	= enic_get_stats,
+	.ndo_validate_addr	= eth_validate_addr,
+	.ndo_set_rx_mode_async	= enic_set_vf_rx_mode,
+	.ndo_set_mac_address	= enic_set_mac_address_dynamic,
+	.ndo_change_mtu		= enic_change_mtu,
+	.ndo_vlan_rx_add_vid	= enic_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid	= enic_vlan_rx_kill_vid,
+	.ndo_tx_timeout		= enic_tx_timeout,
+	.ndo_set_vf_port	= enic_set_vf_port,
+	.ndo_get_vf_port	= enic_get_vf_port,
+	.ndo_set_vf_mac		= enic_set_vf_mac,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+	.ndo_poll_controller	= enic_poll_controller,
+#endif
+#ifdef CONFIG_RFS_ACCEL
+	.ndo_rx_flow_steer	= enic_rx_flow_steer,
+#endif
+	.ndo_features_check	= enic_features_check,
+};
+
 static const struct net_device_ops enic_netdev_ops = {
 	.ndo_open		= enic_open,
 	.ndo_stop		= enic_stop,
@@ -4377,7 +4847,9 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 */
 	enic->rx_coalesce_usecs = enic->tx_coalesce_usecs;
 
-	if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic))
+	if (enic_is_sriov_vf_v2(enic))
+		netdev->netdev_ops = &enic_netdev_vf_v2_ops;
+	else if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic))
 		netdev->netdev_ops = &enic_netdev_dynamic_ops;
 	else
 		netdev->netdev_ops = &enic_netdev_ops;
@@ -4541,9 +5013,12 @@ static void enic_remove(struct pci_dev *pdev)
 
 		/* Close the admin channel and unregister from the PF before
 		 * unregister_netdev() to prevent a late PF notification from
-		 * touching a netdev that is being torn down. VF_UNREGISTER is the
+		 * touching a netdev that is being torn down.  VF_UNREGISTER is the
 		 * protocol teardown operation: the PF removes all VF-requested
 		 * configuration, including the station address, before replying.
+		 * Detach first while holding RTNL so any running asynchronous
+		 * receive-mode update has completed and queued updates cannot enter
+		 * the mailbox callback.
 		 */
 		if (enic_is_sriov_vf_v2(enic)) {
 			enic_vf_admin_mac_quiesce(enic);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH net-next v6 3/7] enic: recover V2 VF mailbox after request failure
  2026-12-04 15:29 ` [PATCH net-next v6 3/7] enic: recover V2 VF mailbox after request failure Satish Kharat
@ 2026-12-05 16:28   ` netdev-bot+sashiko
  0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 16:28 UTC (permalink / raw)
  To: satishkh
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
	netdev, linux-kernel, sebaddel, aradhana, rfaucett, sdf

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The subject and framing describe V2 VF mailbox recovery, but
  the patch also changes reset and stop behaviour for every enic…
- [Medium] A mailbox fault that arrives while enic_reset() or
  enic_hang_reset() is reopening a V2 VF, after the re-registration in…
- [Medium] __enic_stop() clears datapath_open on entry and then jumps to
  stop_failed at the first failing vnic_wq_disable() or…
- [Low] vnic_dev_hang_reset() no longer sends CMD_INIT after its
  SOFT_RESET fallback.
- [Low] enic: duplicated recovery logic and dead reopen checks in reset
  handlers

--

enic: recover V2 VF mailbox after request failure

This commit adds recovery for the V2 VF mailbox after a lost or
inconsistent reply, or after a send-completion timeout. Recovery runs on
a dedicated work item that shares the hang-reset sequence with the Tx
watchdog. The commit also reworks the reset paths to check stop, reset,
INIT and reopen results, and adds a datapath_open latch and an RX
quarantine gate.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index dde9098357d16..587c340854cb2 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c

[ ... ]

> @@ -1841,12 +1929,17 @@ static int enic_open(struct net_device *netdev)
>  }
>  
>  /* rtnl lock is held, process context */
> -static int enic_stop(struct net_device *netdev)
> +static int __enic_stop(struct net_device *netdev)
>  {
>  	struct enic *enic = netdev_priv(netdev);
>  	unsigned int i;
>  	int err;
>  
> +	/* IFF_UP can outlive a failed internal recovery. Stop software once. */
> +	if (!READ_ONCE(enic->datapath_open))
> +		return 0;
> +	WRITE_ONCE(enic->datapath_open, false);
> +

[ ... ]

> @@ -1871,23 +1964,25 @@ static int enic_stop(struct net_device *netdev)
>  			napi_disable(&enic->napi[enic_cq_wq(enic, i)]);
>  	netif_tx_disable(netdev);
>  
> +	/* Detach IRQ callbacks even if a later queue disable fails. */
> +	enic_unset_affinity_hint(enic);
> +	enic_free_intr(enic);
> +
>  	if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
>  		enic_dev_del_station_addr(enic);
>  
>  	for (i = 0; i < enic->wq_count; i++) {
>  		err = vnic_wq_disable(&enic->wq[i].vwq);
>  		if (err)
> -			return err;
> +			goto stop_failed;
>  	}
>  	for (i = 0; i < enic->rq_count; i++) {
>  		err = vnic_rq_disable(&enic->rq[i].vrq);
>  		if (err)
> -			return err;
> +			goto stop_failed;
>  	}
>  
>  	enic_dev_notify_unset(enic);

[ ... ]

> @@ -1902,6 +1997,18 @@ static int enic_stop(struct net_device *netdev)
>  		vnic_intr_clean(&enic->intr[i]);
>  
>  	return 0;
> +
> +stop_failed:
> +	/* Prevent another open from treating this partial stop as a clean one.
> +	 * Generic queue DMA lifetime after a stop failure is separate work.
> +	 */
> +	enic_detach_after_recovery_failure(enic);
> +	return err;
> +}

[Severity: Medium]
Does this path leave the remaining queues enabled, and leak the RQ page
pools and in-flight TX skbs?

datapath_open is cleared on entry. The first failing vnic_wq_disable()
or vnic_rq_disable() then jumps to stop_failed and skips:

  - the remaining WQ and RQ disables
  - enic_dev_notify_unset()
  - vnic_wq_clean() for the TX skbs and their DMA mappings
  - vnic_rq_clean() and page_pool_destroy()
  - the CQ and intr cleans

The unwind in enic_open() keeps disabling every queue after a failure,
so the two paths now behave differently.

Because datapath_open is already false, a later remove does not retry
the stop:

enic_remove()
  unregister_netdev()
    enic_stop()
      __enic_stop()                <- returns 0, !datapath_open
  enic_dev_deinit()
    enic_free_vnic_resources()     <- frees rings of queues never disabled
  enic_dev_close()

Also, enic_reset() no longer soft resets the device after a stop
failure. It abandons recovery instead.

The queues after the first failing one are not stuck. Could they still
be disabled? Could the rings be freed only after CMD_CLOSE when the stop
failed?

[ ... ]

> @@ -2271,135 +2497,343 @@ static void enic_admin_chan_reopen(struct enic *enic)

[ ... ]

> +static bool enic_vf_mbox_recovery_finish(struct enic *enic, bool succeeded)
> +{
> +	bool restart;
> +
> +	spin_lock_bh(&enic->mbox_state_lock);
> +	/* Restart only for a fault still outstanding after recovery. Fresh
> +	 * registration may already have consumed a fault from the old channel.
> +	 * A failed handshake remains quarantined for an external recovery event.
> +	 */
> +	restart = succeeded &&
> +		  (READ_ONCE(enic->vf_mbox_reconnect_required) ||
> +		   READ_ONCE(enic->mbox_tx_poisoned));
> +	enic->vf_mbox_recovery_active = false;
> +	spin_unlock_bh(&enic->mbox_state_lock);
> +
> +	return restart;
>  }

[Severity: Medium]
Can a mailbox fault in the reopen window leave a V2 VF down with no
follow-up recovery?

The window opens after enic_admin_chan_reopen() has re-registered and
closes at the final check in enic_open():

enic_hang_reset() or enic_reset()
  enic_vf_mbox_recovery_begin()      <- sets vf_mbox_recovery_active
  enic_admin_chan_reopen()           <- registration succeeds
  fault: admin_rx_lost, vf_ack_work send timeout, ...
    enic_mbox_vf_kick_recovery()     <- no schedule, recovery active
  enic_open()
    final mailbox state check        <- returns -EIO
  enic_admin_channel_close()
  enic_vf_mbox_recovery_finish(enic, false)   <- restart is false

The VF is left in this state:

  - IFF_UP set
  - datapath_open false
  - carrier off
  - RX quarantined
  - admin channel down

With no admin channel, no new fault can be raised. The Tx watchdog needs
carrier. Nothing queues vf_mbox_recovery_work again.

If the same fault arrives just after the final check passes, it does get
a restart. Later in the series, enic_open() also sends station-address
and packet-filter requests, which widens this window. The final version
still uses "restart = succeeded && ...".

Should a transient fault after a successful handshake be handled
differently from a PF that cannot complete registration at all?

[ ... ]

> +	err = enic_dev_soft_reset(enic);
> +	if (err) {
> +		enic_detach_after_recovery_failure(enic);
> +		goto reset_out;
> +	}
> +	/* Firmware completes SOFT_RESET in OPEN state.  Non-dynamic vNICs need
> +	 * CMD_INIT to recreate and enable their LIF before resource restore.
> +	 */
> +	if (!enic_is_dynamic(enic)) {
> +		err = enic_vnic_dev_init(enic);
> +		if (err) {
> +			netdev_err(enic->netdev,
> +				   "vNIC init after soft reset failed: %d\n",
> +				   err);
> +			enic_detach_after_recovery_failure(enic);
> +			goto reset_out;
> +		}
> +	}
>  
> -	enic_dev_soft_reset(enic);
>  	enic_reset_addr_lists(enic);

[Severity: Medium]
The subject and most of the commit message describe V2 VF mailbox
recovery. Several changes in this patch apply to every enic function,
though, including PFs, standalone vNICs and dynamic vNICs:

  - enic_reset() now sends CMD_INIT through enic_vnic_dev_init() after
    SOFT_RESET for every non-dynamic function. The old code never did
    this.
  - On any function, a failed soft reset, hang reset or INIT, or a
    queue-disable failure in __enic_stop(), now calls
    netif_device_detach(). Before, the error was ignored and the
    datapath was reopened.
  - The legacy vnic_dev_hang_reset() fallback no longer sends INIT
    itself.
  - enic_reset_addr_lists() now takes netif_addr_lock_bh().
  - Soft reset start and status now run under devcmd_lock. The new
    comment says the old code could collide with CMD_STATS_DUMP and
    report a false failure.

For example, one transient devcmd timeout during queue-error recovery
on a standalone NIC now leaves the interface detached until the driver
is rebound. Before this patch, the interface was reopened.

The V2 PF SR-IOV enable path is still dormant, since
enic_sriov_configure() is __maybe_unused. For PF and non-SR-IOV users,
these generic changes are the only part of the patch that takes effect.

The locking changes look like fixes for older bugs, and the INIT change
is either a fix or a new firmware command on every PF reset. Could these
be split into their own patches with Fixes: tags? Could the commit
message also describe the new behaviour for non-VF functions?

[ ... ]

> diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.c b/drivers/net/ethernet/cisco/enic/vnic_dev.c
> index 92eec1455ceb8..a78bd58f950f5 100644
> --- a/drivers/net/ethernet/cisco/enic/vnic_dev.c
> +++ b/drivers/net/ethernet/cisco/enic/vnic_dev.c
> @@ -721,17 +721,23 @@ int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg)
>  {
>  	u64 a0 = (u32)arg, a1 = 0;
>  	int wait = 1000;
> -	int err;
>  
> +	vdev->hang_reset_uses_soft_reset = false;
>  	if (vnic_dev_capable(vdev, CMD_HANG_RESET)) {
>  		return vnic_dev_cmd(vdev, CMD_HANG_RESET,
>  				&a0, &a1, wait);
> -	} else {
> -		err = vnic_dev_soft_reset(vdev, arg);
> -		if (err)
> -			return err;
> -		return vnic_dev_init(vdev, 0);
>  	}
> +
> +	/* enic_dev_wait() polls SOFT_RESET_STATUS. INIT follows reset completion
> +	 * in the driver, after the ordinary close has succeeded.
> +	 */
> +	vdev->hang_reset_uses_soft_reset = true;
> +	return vnic_dev_soft_reset(vdev, arg);
>  }

[Severity: Low]
Is this comment accurate? Its only caller, enic_hang_reset(), sends INIT
only when:

	if (needs_init && !enic_is_dynamic(enic)) {

enic_dev_hang_reset() also forces needs_init to false for V2 VFs.

So on firmware without CMD_HANG_RESET, a dynamic vNIC now gets a bare
SOFT_RESET and no INIT. The old helper always called vnic_dev_init().

The commit message says dynamic vNICs follow their probe-time
initialization contract, and enic_probe() matches that. Could this
comment say which functions receive INIT afterwards, so the helper and
its caller agree on who owns INIT?

[ ... ]

> @@ -2271,135 +2497,343 @@ static void enic_admin_chan_reopen(struct enic *enic)
>  		 */
>  		schedule_work(&enic->link_notify_work);
>  	}
> +
> +	return 0;
> +}
> +
> +static bool enic_vf_mbox_recovery_begin(struct enic *enic,
> +					bool mailbox_recovery)
> +{
> +	bool claimed = false;
> +
> +	/* Reset workers claim ownership only after taking RTNL. This state
> +	 * lock still makes the handoff atomic with mailbox fault producers.
> +	 */
> +	spin_lock_bh(&enic->mbox_state_lock);
> +	/* Open may have consumed a queued mailbox fault while holding RTNL. */
> +	if (!enic->vf_mbox_recovery_active &&
> +	    (!mailbox_recovery ||
> +	     READ_ONCE(enic->vf_mbox_reconnect_required) ||
> +	     READ_ONCE(enic->mbox_tx_poisoned))) {
> +		enic->vf_mbox_recovery_active = true;
> +		WRITE_ONCE(enic->vf_rx_quarantined, true);
> +		claimed = true;
> +	}
> +	spin_unlock_bh(&enic->mbox_state_lock);
> +
> +	return claimed;
> +}
> +
> +static bool enic_vf_mbox_recovery_finish(struct enic *enic, bool succeeded)
> +{
> +	bool restart;
> +
> +	spin_lock_bh(&enic->mbox_state_lock);
> +	/* Restart only for a fault still outstanding after recovery. Fresh
> +	 * registration may already have consumed a fault from the old channel.
> +	 * A failed handshake remains quarantined for an external recovery event.
> +	 */
> +	restart = succeeded &&
> +		  (READ_ONCE(enic->vf_mbox_reconnect_required) ||
> +		   READ_ONCE(enic->mbox_tx_poisoned));
> +	enic->vf_mbox_recovery_active = false;
> +	spin_unlock_bh(&enic->mbox_state_lock);
> +
> +	return restart;
>  }
>  
>  static void enic_reset(struct work_struct *work)
>  {
>  	struct enic *enic = container_of(work, struct enic, reset);
> +	bool recovery_owned = false;
> +	bool restart = false;
> +	bool reopen;
> +	int stop_err = 0;
> +	int err = 0;
>  
>  	if (!netif_running(enic->netdev))
>  		return;
> -
>  	rtnl_lock();
> -
> -	if (!netif_running(enic->netdev))
> +	reopen = netif_running(enic->netdev);
> +	if (!reopen || !netif_device_present(enic->netdev))
>  		goto unlock;
>  
> -	/* Stop any activity from infiniband */
> +	/* Serialize a live V2 VF protocol recovery and preserve its one bounded
> +	 * late-fault follow-up.
> +	 */
> +	if (reopen && enic_is_sriov_vf_v2(enic)) {
> +		recovery_owned = enic_vf_mbox_recovery_begin(enic, false);
> +		if (!recovery_owned)
> +			goto unlock;
> +	}
> +
> +	/* Stop any activity from infiniband. */
>  	enic_set_api_busy(enic, true);
>  
> -	/* Close the V2 admin/MBOX channel before the soft reset. Release its
> -	 * DMA resources only after both queues report stopped; otherwise
> -	 * quarantine the channel and abandon the reset.
> +	/* Close the admin channel before reset without sending DEL_MAC; reset and
> +	 * fresh registration discard the old VF-requested state. Release its DMA
> +	 * resources only after both queues report stopped. Otherwise quarantine
> +	 * the channel and abandon the reset.
>  	 */
>  	if (enic_has_admin_chan(enic)) {
> -		enic_admin_channel_close(enic);
> +		int close_err = enic_admin_channel_close(enic);
> +
> +		if (close_err && enic_admin_channel_is_quarantined(enic))
> +			netdev_err(enic->netdev,
> +				   "Admin queue did not stop: %d\n", close_err);
> +		else if (close_err)
> +			netdev_warn(enic->netdev,
> +				    "Admin QP disable returned: %d\n",
> +				    close_err);
>  		/* Channel close has drained registration replies. */
>  		if (enic_is_sriov_vf_v2(enic))
>  			WRITE_ONCE(enic->vf_registered, false);
>  	}
> -	if (enic_admin_channel_is_quarantined(enic)) {
> -		/* Core close excludes netpoll and clears __LINK_STATE_START first. */
> -		dev_close(enic->netdev);
> -		goto reset_out;
> -	}
> +	if (READ_ONCE(enic->datapath_open))
> +		stop_err = __enic_stop(enic->netdev);
>  
> -	enic_stop(enic->netdev);
>  	if (enic_is_sriov_vf_v2(enic))
>  		enic_mbox_vf_link_state_reset(enic);
> +	if (stop_err || enic_control_dma_unresolved(enic)) {
> +		err = stop_err ?: -EBUSY;
> +		netdev_err(enic->netdev,
> +			   "Recovery blocked after close (datapath stop %d)\n",
> +			   stop_err);
> +		goto reset_out;
> +	}
> +
> +	err = enic_dev_soft_reset(enic);
> +	if (err) {
> +		enic_detach_after_recovery_failure(enic);
> +		goto reset_out;
> +	}
> +	/* Firmware completes SOFT_RESET in OPEN state.  Non-dynamic vNICs need
> +	 * CMD_INIT to recreate and enable their LIF before resource restore.
> +	 */
> +	if (!enic_is_dynamic(enic)) {
> +		err = enic_vnic_dev_init(enic);
> +		if (err) {
> +			netdev_err(enic->netdev,
> +				   "vNIC init after soft reset failed: %d\n",
> +				   err);
> +			enic_detach_after_recovery_failure(enic);
> +			goto reset_out;
> +		}
> +	}
>  
> -	enic_dev_soft_reset(enic);
>  	enic_reset_addr_lists(enic);
>  	enic_init_vnic_resources(enic);
>  	enic_set_rss_nic_cfg(enic);
>  	enic_dev_set_ig_vlan_rewrite_mode(enic);
>  	enic_ext_cq(enic);
>  
> -	if (enic_open(enic->netdev))
> +	/* A V2 VF registers with the PF before reopening its datapath.
> +	 * A V2 PF rebuilds its admin channel after datapath open.
> +	 */
> +	if (enic_is_sriov_vf_v2(enic)) {
> +		err = enic_admin_chan_reopen(enic);
> +		if (err)
> +			goto reset_out;
> +	}
> +
> +	if (reopen)
> +		err = enic_open(enic->netdev);
> +	if (reopen && err) {
> +		if (enic_is_sriov_vf_v2(enic) && enic_has_admin_chan(enic)) {
> +			int close_err = enic_admin_channel_close(enic);
> +
> +			WRITE_ONCE(enic->vf_registered, false);
> +			if (close_err)
> +				netdev_warn(enic->netdev,
> +					    "Admin close after datapath reopen failure returned: %d\n",
> +					    close_err);
> +		}
> +		netdev_err(enic->netdev,
> +			   "Failed to reopen datapath after reset: %d\n", err);
>  		goto reset_out;
> +	}
>  
> -	/* Re-establish the admin/MBOX channel after the data path is back up.
> -	 * It was fully torn down by enic_admin_channel_close() above;
> -	 * enic_admin_chan_reopen() reopens it and, for a PF re-pushes link
> -	 * state, or for a VF re-runs the probe-time PF handshake.
> +	/* A PF reopens its admin channel after the datapath and re-pushes link
> +	 * state.  The VF handshake, which open depends on, completed above.
>  	 */
> -	if (enic_has_admin_chan(enic))
> -		enic_admin_chan_reopen(enic);
> -	if (enic_is_sriov_vf_v2(enic) &&
> -	    enic_admin_channel_is_quarantined(enic))
> -		dev_close(enic->netdev);
> +	if (enic_has_admin_chan(enic) && !enic_is_sriov_vf_v2(enic)) {
> +		int admin_err = enic_admin_chan_reopen(enic);
> +
> +		if (admin_err)
> +			netdev_err(enic->netdev,
> +				   "Failed to reopen PF admin channel after reset: %d\n",
> +				   admin_err);
> +		if (!err)
> +			err = admin_err;
> +	}
>  
>  reset_out:
>  	/* Allow infiniband to fiddle with the device again */
>  	enic_set_api_busy(enic, false);
>  
> -	call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
> +	if (reopen)
> +		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
>  
>  unlock:
> +	if (recovery_owned)
> +		restart = enic_vf_mbox_recovery_finish(enic,
> +						       !err &&
> +						       !enic_control_dma_unresolved(enic));
>  	rtnl_unlock();
> +	if (restart)
> +		schedule_work(&enic->vf_mbox_recovery_work);
>  }
>  
> -static void enic_tx_hang_reset(struct work_struct *work)
> +static void enic_hang_reset(struct enic *enic, bool mailbox_recovery)
>  {
> -	struct enic *enic = container_of(work, struct enic, tx_hang_reset);
> +	bool recovery_owned = false;
> +	bool restart = false;
> +	bool needs_init;
> +	bool reopen;
> +	int stop_err = 0;
> +	int err = 0;
>  
>  	rtnl_lock();
> -
> -	if (!netif_running(enic->netdev))
> +	reopen = netif_running(enic->netdev);
> +	if (!reopen || !netif_device_present(enic->netdev))
>  		goto unlock;
> +	if (reopen && enic_is_sriov_vf_v2(enic)) {
> +		recovery_owned = enic_vf_mbox_recovery_begin(enic,
> +							     mailbox_recovery);
> +		if (!recovery_owned)
> +			goto unlock;
> +	}
>  
> -	/* Stop any activity from infiniband */
> +	/* Stop any activity from infiniband. */
>  	enic_set_api_busy(enic, true);
>  
> -	/* Close the V2 admin/MBOX channel before the hang reset. Release its
> -	 * DMA resources only after both queues report stopped; otherwise
> -	 * quarantine the channel and abandon the reset.
> +	/* Report an actual Tx hang before stopping and cleaning its queue. Mailbox
> +	 * recovery reuses the VF-allowed hang-reset pair but must not report a
> +	 * spurious Tx hang. As in the soft-reset path, skip DEL_MAC because reset
> +	 * and fresh registration are the cleanup boundary. Release admin DMA only
> +	 * after both queues report stopped; otherwise quarantine the channel and
> +	 * abandon the reset.
>  	 */
> +	if (!mailbox_recovery)
> +		enic_dev_hang_notify(enic);
>  	if (enic_has_admin_chan(enic)) {
> -		enic_admin_channel_close(enic);
> +		int close_err = enic_admin_channel_close(enic);
> +
> +		if (close_err && enic_admin_channel_is_quarantined(enic))
> +			netdev_err(enic->netdev,
> +				   "Admin queue did not stop: %d\n", close_err);
> +		else if (close_err)
> +			netdev_warn(enic->netdev,
> +				    "Admin QP disable returned: %d\n",
> +				    close_err);
>  		/* Channel close has drained registration replies. */
>  		if (enic_is_sriov_vf_v2(enic))
>  			WRITE_ONCE(enic->vf_registered, false);
>  	}
> -	if (enic_admin_channel_is_quarantined(enic)) {
> -		dev_close(enic->netdev);
> -		goto reset_out;
> -	}
> -
> -	enic_dev_hang_notify(enic);
> -	enic_stop(enic->netdev);
> +	if (READ_ONCE(enic->datapath_open))
> +		stop_err = __enic_stop(enic->netdev);
>  	if (enic_is_sriov_vf_v2(enic))
>  		enic_mbox_vf_link_state_reset(enic);
> +	if (stop_err || enic_control_dma_unresolved(enic)) {
> +		err = stop_err ?: -EBUSY;
> +		netdev_err(enic->netdev,
> +			   "Recovery blocked after close (datapath stop %d)\n",
> +			   stop_err);
> +		goto hang_reset_out;
> +	}
>  
> -	enic_dev_hang_reset(enic);
> +	err = enic_dev_hang_reset(enic, &needs_init);
> +	if (err) {
> +		enic_detach_after_recovery_failure(enic);
> +		goto hang_reset_out;
> +	}
> +	/* Native HANG_RESET preserves firmware's desired admin state and the
> +	 * firmware reinitializes it.  Only the legacy SOFT_RESET fallback sets
> +	 * needs_init and requires the deferred CMD_INIT below.
> +	 */
> +	if (needs_init && !enic_is_dynamic(enic)) {
> +		err = enic_vnic_dev_init(enic);
> +		if (err) {
> +			netdev_err(enic->netdev,
> +				   "vNIC init after hang reset failed: %d\n",
> +				   err);
> +			enic_detach_after_recovery_failure(enic);
> +			goto hang_reset_out;
> +		}
> +	}
>  	enic_reset_addr_lists(enic);
>  	enic_init_vnic_resources(enic);
>  	enic_set_rss_nic_cfg(enic);
>  	enic_dev_set_ig_vlan_rewrite_mode(enic);
>  	enic_ext_cq(enic);
>  
> -	if (enic_open(enic->netdev))
> -		goto reset_out;
> +	if (enic_is_sriov_vf_v2(enic)) {
> +		err = enic_admin_chan_reopen(enic);
> +		if (err)
> +			goto hang_reset_out;
> +	}
> +
> +	if (reopen)
> +		err = enic_open(enic->netdev);
> +	if (reopen && err) {
> +		if (enic_is_sriov_vf_v2(enic) && enic_has_admin_chan(enic)) {
> +			int close_err = enic_admin_channel_close(enic);
>  
> -	/* Re-establish the admin/MBOX channel after the data path is back up.
> -	 * It was fully torn down by enic_admin_channel_close() above;
> -	 * enic_admin_chan_reopen() reopens it and, for a PF re-pushes link
> -	 * state, or for a VF re-runs the probe-time PF handshake.
> +			WRITE_ONCE(enic->vf_registered, false);
> +			if (close_err)
> +				netdev_warn(enic->netdev,
> +					    "Admin close after datapath reopen failure returned: %d\n",
> +					    close_err);
> +		}
> +		netdev_err(enic->netdev,
> +			   "Failed to reopen datapath after hang reset: %d\n", err);
> +		goto hang_reset_out;
> +	}
> +
> +	/* A PF reopens its admin channel after the datapath and re-pushes link
> +	 * state.  The VF handshake, which open depends on, completed above.
>  	 */
> -	if (enic_has_admin_chan(enic))
> -		enic_admin_chan_reopen(enic);
> -	if (enic_is_sriov_vf_v2(enic) &&
> -	    enic_admin_channel_is_quarantined(enic))
> -		dev_close(enic->netdev);
> +	if (enic_has_admin_chan(enic) && !enic_is_sriov_vf_v2(enic)) {
> +		int admin_err = enic_admin_chan_reopen(enic);
>  
> -reset_out:
> +		if (admin_err)
> +			netdev_err(enic->netdev,
> +				   "Failed to reopen PF admin channel after hang reset: %d\n",
> +				   admin_err);
> +		if (!err)
> +			err = admin_err;
> +	}
> +
> +hang_reset_out:
>  	/* Allow infiniband to fiddle with the device again */
>  	enic_set_api_busy(enic, false);
>  
> -	call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
> +	if (reopen)
> +		call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
>  
>  unlock:
> +	if (recovery_owned)
> +		restart = enic_vf_mbox_recovery_finish(enic,
> +						       !err &&
> +						       !enic_control_dma_unresolved(enic));
>  	rtnl_unlock();
> +	if (restart)
> +		schedule_work(&enic->vf_mbox_recovery_work);
> +}
> +
> +static void enic_tx_hang_reset(struct work_struct *work)
> +{
> +	struct enic *enic = container_of(work, struct enic, tx_hang_reset);
> +
> +	enic_hang_reset(enic, false);
> +}
> +
> +static void enic_vf_mbox_recovery_work(struct work_struct *work)
> +{
> +	struct enic *enic = container_of(work, struct enic,
> +					vf_mbox_recovery_work);
> +
> +	enic_hang_reset(enic, true);
>  }
>  
>  static int enic_set_intr_mode(struct enic *enic)

[Severity: Low]
enic_reset() and enic_hang_reset() are now almost line-for-line
copies of each other. Both do the following:

  - take RTNL and check netif_running() and netif_device_present()
  - claim recovery with enic_vf_mbox_recovery_begin()
  - close the admin channel, with the same logging
  - call __enic_stop() and enic_mbox_vf_link_state_reset()
  - run the same blocked-recovery check
  - re-init the vNIC resources
  - reopen the VF admin channel
  - call enic_open(), with the same admin-close rollback on failure
  - reopen the PF admin channel and send NETDEV_REBOOT
  - call enic_vf_mbox_recovery_finish() and queue the
    vf_mbox_recovery_work follow-up

The only real differences are:

  - enic_dev_hang_notify() for a genuine Tx hang
  - SOFT_RESET followed by INIT on every non-dynamic function, versus
    HANG_RESET with INIT only when needs_init is set
  - the mailbox_recovery argument passed to
    enic_vf_mbox_recovery_begin()

This sequence has subtle ordering between the admin channel, the
datapath and mbox_state_lock. With two copies, the paths can easily
drift apart. Later in the series, the receive-mode replay after
reopen already had to be added to both functions.

There is also dead code. Both functions set reopen from
netif_running() and jump to unlock when it is false. Nothing changes
reopen after that, so every later test of it is always true. That
covers four checks in each function:

  - the check before the recovery claim
  - the check before enic_open()
  - the check on the open error path
  - the check before the NETDEV_REBOOT notifier

These checks suggest a case where recovery runs without reopening,
but no such case exists.

Could the shared sequence move into one helper that takes the reset
type, with the two work functions only choosing it? If reopen is
meant to cover a device that is not running, which path is that?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-enic-sriov-v2-vf-receive-control-v6-0-ca38950bbe07%40cisco.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH net-next v6 4/7] enic: validate V2 VF configuration replies
  2026-12-04 15:29 ` [PATCH net-next v6 4/7] enic: validate V2 VF configuration replies Satish Kharat
@ 2026-12-05 16:28   ` netdev-bot+sashiko
  0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 16:28 UTC (permalink / raw)
  To: satishkh
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
	netdev, linux-kernel, sebaddel, aradhana, rfaucett, sdf

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The ADD_DEL_MAC reply handler and the SET_PKT_FILTER reply
  handler apply different recovery policies to the same kind of failure,…
- [Low] This patch adds ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF/ACK and struct
  enic_mbox_pf_set_admin_mac_notif_msg, and enic_mbox_vf_malformed_msg()…
- [Low] enic_mbox_vf_set_pkt_filter() always includes
  CMD_PFILTER_DIRECTED in `required`, so a directed=0 request that the…
- [Low] The new reply handlers enic_mbox_vf_handle_add_del_mac_reply()
  and enic_mbox_vf_handle_set_pkt_filter_reply() name their length…

--

enic: validate V2 VF configuration replies

This adds the VF side of the V2 mailbox ADD_DEL_MAC and SET_PKT_FILTER
operations, along with the administrative MAC protocol definitions. Each
reply is checked for framing, echoed operations, result counts and applied
filter flags. A malformed reply, or one reporting that the VF is no longer
registered, forces a new VF registration.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
> index 3579d2980a246..c042cd2769dd5 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c

[ ... ]

> @@ -605,16 +680,166 @@ static void enic_mbox_vf_handle_reply(struct enic *enic, u8 reply_type,

[ ... ]

> +static void enic_mbox_vf_handle_add_del_mac_reply(struct enic *enic,
> +						  void *payload, u16 msg_len,
> +						  u64 msg_num)
> +{

[Severity: Low]
This isn't a bug, but the msg_len parameter here actually receives the
payload length. The same is true in
enic_mbox_vf_handle_set_pkt_filter_reply(). enic_mbox_vf_process_msg()
calls it like this:

	enic_mbox_vf_handle_add_del_mac_reply(enic, payload,
					      payload_len, msg_num);

Elsewhere in this file, enic_mbox_pf_process_msg() and
enic_mbox_recv_handler() use msg_len for le16_to_cpu(hdr->msg_len), and
that value includes the header.

The bounds checks are correct for a payload length today. Could the
parameter be renamed to payload_len? That would make it less likely that
a later change checks the peer-supplied mac_addr[] size against the wrong
length.

> +	struct enic_mbox_vf_add_del_mac_reply_msg *reply = payload;
> +	enum enic_mbox_vf_reply_recovery recovery;

[ ... ]

> +	if (msg_len < sizeof(*reply)) {
> +		status = enic_mbox_vf_classify_reply(true, 0, &recovery);
> +	} else {
> +		ret_major = le16_to_cpu(reply->reply.ret_major);
> +		ret_minor = le16_to_cpu(reply->reply.ret_minor);
> +		status = enic_mbox_vf_classify_reply(false, ret_major,
> +						     &recovery);
> +	}
> +	if (status)
> +		goto claim;

[Severity: Medium]
Should an errno-style ret_major be treated as indeterminate here, as it
is for packet filters?

If ret_major has bits outside ENIC_MBOX_ERR_MASK,
enic_mbox_vf_classify_reply() returns -EIO and leaves recovery at
ENIC_MBOX_VF_REPLY_OK. The goto then skips the per-entry checks, so the
caller gets a plain -EIO and no reconnect happens.

enic_mbox_vf_handle_set_pkt_filter_reply() handles the same condition by
forcing a reconnect:

	if (status && (ret_major & ~ENIC_MBOX_ERR_MASK))
		recovery = ENIC_MBOX_VF_REPLY_RECONNECT;

An errno-style MAC reply has no per-entry results either. The VF cannot
tell which of up to ENIC_MBOX_MAX_MAC_OPS entries the PF applied. The
commit message says:

    A coherent top-level MAC-operation failure remains an ordinary error.
    Reserve reconnect for malformed or indeterminate replies and explicit
    registration loss.

Nothing on this path checks whether the top-level failure is coherent.

Later in the series, enic_vf_sync_mac_filters() reconnects in the caller
when a request that includes a delete fails with a request-wide -EIO.
enic_vf_station_addr_replace() in enic_main.c does not reconnect:

	err = enic_mbox_vf_add_del_macs(enic, macs, num_macs);
	if (err) {
		if (READ_ONCE(enic->mbox_tx_poisoned))
			enic_mbox_vf_link_state_set_running(enic, false);
		return err;
	}

Every request it sends is a DEL+ADD (or DEL+DEL+ADD) compound. Suppose a
PF applies part of one and then returns an errno-style ret_major. Could
the VF then believe the old station filter is still installed, with no
re-registration to correct it?

The final patch in the series says supported PFs reject whole requests
before applying any operations. The VF side doesn't enforce that.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-enic-sriov-v2-vf-receive-control-v6-0-ca38950bbe07%40cisco.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH net-next v6 5/7] net: add dev_addr_set_sync() for driver address updates
  2026-12-04 15:29 ` [PATCH net-next v6 5/7] net: add dev_addr_set_sync() for driver address updates Satish Kharat
@ 2026-12-05 16:28   ` netdev-bot+sashiko
  0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 16:28 UTC (permalink / raw)
  To: satishkh
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
	netdev, linux-kernel, sebaddel, aradhana, rfaucett, sdf

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The concern: dev_addr_set_sync() is exported with
  EXPORT_SYMBOL_GPL from net/core/dev_api.c and declared in…
- [Low] The concern: dev_addr_set_sync() requires RTNL held and the
  device instance lock not held.
- [Low] The concern: dev_addr_set_sync() changes dev->dev_addr and the
  dev->dev_addrs rbtree under RTNL and dev_addr_sem only, and it forbids…

--

net: add dev_addr_set_sync() for driver address updates

This adds an exported helper, dev_addr_set_sync(), for drivers that
publish a new primary device address while holding RTNL. It takes
dev_addr_sem for writing around dev_addr_set(), so the update is
serialized with the sysfs and SIOCGIFHWADDR readers. It also asserts
that the caller holds neither dev_addr_sem nor the device instance lock.

> diff --git a/net/core/dev_api.c b/net/core/dev_api.c
> index 437947dd08ed5..081e9cb063b69 100644
> --- a/net/core/dev_api.c
> +++ b/net/core/dev_api.c
> @@ -85,6 +85,27 @@ void dev_set_group(struct net_device *dev, int new_group)
>  	netdev_unlock_ops(dev);
>  }
>  
> +/**
> + * dev_addr_set_sync() - publish a driver-selected device address
> + * @dev: device whose address is being updated
> + * @addr: new address, with dev->addr_len bytes
> + *
> + * Serialize the update with sysfs and SIOCGIFHWADDR readers.
> + * The caller holds RTNL and must hold neither dev_addr_sem nor the
> + * device instance lock.
> + */
> +void dev_addr_set_sync(struct net_device *dev, const u8 *addr)

[Severity: Low]
This isn't a bug, but is the dev_ prefix a good fit for this helper?

Documentation/networking/netdevices.rst describes the dev_xxx/netdev_xxx
functions as the ones that take the instance lock themselves. The peer
writer dev_set_mac_address_user() does take it:

	down_write(&dev_addr_sem);
	netdev_lock_ops(dev);
	ret = netif_set_mac_address(dev, ss, extack);

dev_addr_set_sync() instead requires that the instance lock is not held.

That said, the instance lock does not seem to cover dev->dev_addr or
dev->dev_addrs. Neither field appears in the @lock kernel-doc of struct
net_device, and dev_addr_add() already changes the same dev_addrs tree
with only RTNL held. The existing dev_addr_* helpers don't follow the
dev_xxx naming rule either. So this looks like a naming question, not
a race.

> +{
> +	ASSERT_RTNL();
> +	lockdep_assert_not_held(&dev_addr_sem);
> +	lockdep_assert_not_held(&dev->lock);

[Severity: Low]
With this contract, can ops-locked drivers use the helper from deferred
work at all? Documentation/networking/netdevices.rst says:

ndo_work:
	Synchronization: netdev instance lock for "ops locked" drivers,
	rtnl_lock() semaphore for all other drivers.

An ops-locked driver running from netdev_work_proc() would hold dev->lock
and not RTNL. It would fail both ASSERT_RTNL() and the dev->lock
assertion here.

A caller that ignored the contract and held dev->lock would take
dev->lock before dev_addr_sem. That is the reverse of the order used in
dev_set_mac_address_user() and do_setlink():

	/* dev_addr_sem is an outer lock, enforce proper ordering */
	down_write(&dev_addr_sem);
	netdev_lock_ops(dev);

Lockdep would catch this through the assertions above.

The only user in the series is enic, which isn't ops-locked. In
enic_vf_admin_mac_work() it takes RTNL with rtnl_trylock() and doesn't
hold dev->lock, so it meets the contract.

Is it intended that only non-ops-locked callers can use the helper? If
so, could the kernel-doc say so?

> +
> +	down_write(&dev_addr_sem);
> +	dev_addr_set(dev, addr);
> +	up_write(&dev_addr_sem);
> +}
> +EXPORT_SYMBOL_GPL(dev_addr_set_sync);

[Severity: Low]
Nothing calls dev_addr_set_sync() at this commit. Could the commit
message name the intended user?

The later patch "enic: manage V2 VF station and administrative MAC"
calls it from enic_vf_admin_mac_work() and enic_vf_admin_mac_refresh().
So the export is used by the end of the series.

The commit message describes the problem in general terms:

    Drivers that publish a new address in
    response to firmware can bypass the write-side lock taken by the
    userspace MAC setter.

Other drivers with the same pattern still update the address without
dev_addr_sem. Examples are bnxt_update_vf_mac() in bnxt_sriov.c and
drivers/net/vmxnet3/vmxnet3_drv.c. That bypass predates this patch, and
the patch doesn't claim to convert those drivers.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-enic-sriov-v2-vf-receive-control-v6-0-ca38950bbe07%40cisco.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH net-next v6 6/7] enic: manage V2 VF station and administrative MAC
  2026-12-04 15:29 ` [PATCH net-next v6 6/7] enic: manage V2 VF station and administrative MAC Satish Kharat
@ 2026-12-05 16:28   ` netdev-bot+sashiko
  0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 16:28 UTC (permalink / raw)
  To: satishkh
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
	netdev, linux-kernel, sebaddel, aradhana, rfaucett, sdf

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In enic_vf_admin_mac_work()
  (drivers/net/ethernet/cisco/enic/enic_main.c), the nonzero-policy case…
- [Medium] enic: enic_vf_station_recovery_required() blocks VF_UNREGISTER
  on remove
- [Medium] enic: enic_vf_admin_mac_work() disables mailbox sends on
  detached netdev
- [Low] enic: lockless READ_ONCE() on admin MAC flags races with plain
  writes
- [Low] enic: missing 2-byte alignment on struct enic MAC address arrays

--

enic: manage V2 VF station and administrative MAC

The patch makes the V2 VF station address use the mailbox MAC operation,
and keeps it apart from netdev secondary-unicast sync. A replacement is
sent as one compound DEL+ADD request. The patch also adds a worker that
applies PF administrative MAC notifications, refreshes the policy after
registration, and manages the station address across open, stop, reset
and remove.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 587c340854cb2..0ee2ea5b24682 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c

[ ... ]

> +static void enic_vf_admin_mac_work(struct work_struct *work)
> +{

[ ... ]

> +	/* A nonzero notification describes a station address the PF has already
> +	 * installed. Zero delegates selection to the VF, which registers the
> +	 * selected random address through the policy-safe replacement request.
> +	 */
> +	if (!READ_ONCE(enic->datapath_open)) {
> +		station_installed = !zero_policy &&
> +			(!enic->vf_station_addr_valid ||
> +			 ether_addr_equal(enic->vf_station_addr, selected));
> +	} else if (zero_policy) {
> +		mutated = true;
> +		err = enic_vf_station_addr_replace(enic, selected, NULL);
> +		station_installed = !err;
> +	} else if (enic->vf_station_addr_valid &&
> +		   !ether_addr_equal(enic->vf_station_addr, selected)) {
> +		mutated = true;
> +		err = enic_vf_station_addr_del(enic);
> +		station_installed = !err;

[Severity: Medium]
What makes sure the new administrative MAC is actually installed at the PF
as a station filter when this branch runs?

The datapath is open and the policy is nonzero and differs from
vf_station_addr. In that case enic_vf_admin_mac_work() only sends a
mailbox DELETE for the old station through enic_vf_station_addr_del().
No ADD is sent for selected. When the DELETE succeeds, station_installed
is set to true and the code later does:

	if (station_installed)
		enic_vf_station_addr_set(enic, selected);
	enic_vf_station_sync_reset(enic);

The only basis for treating selected as installed is the comment above
the branch. No in-tree PF sends ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF. The PF
admin MAC path, enic_set_vf_mac(), only issues a proxied
vnic_dev_set_mac_addr() (CMD_SET_MAC_ADDR) and adds no address filter.
Neither enic_mbox.h nor the commit message states this contract, and the
commit message says the PF side comes in a later series.

Suppose the PF sends the notification before it installs the address, or
never installs it as a STATION entry. Would the VF then delete its only
confirmed station filter and end up with dev_addr == selected and
vf_station_addr_valid == true, but no exact filter for its own MAC?

enic_vf_station_sync_reset() also drops the core unicast sync reference
for that address. So rx-mode sync would not install the filter either,
and unicast receive to the primary MAC could stay broken until the next
stop/open or re-registration.

The zero-policy branch and enic_vf_station_addr_open() both use
enic_vf_station_addr_replace(), whose final equal-address DEL+ADD is
confirmed by the PF reply. Could the nonzero-policy branch use the same
replacement request instead of assuming the PF has already installed the
address?

> +	} else {
> +		station_installed = true;
> +	}
> +	if (err)
> +		goto unlock;

[Severity: Medium]
If the PF rejects this station DELETE, the new call to
enic_vf_station_recovery_required() goes through
enic_mbox_vf_require_reconnect() to
enic_mbox_vf_mark_reconnect_locked(), which sets mbox_send_disabled.
vf_registered stays true. mbox_tx_poisoned is false because the admin
WQ itself is fine. A partial or contradictory reply in
enic_vf_station_addr_replace() leaves the same state behind.

What clears mbox_send_disabled again after that? The intended cleanup
is the fresh registration done by vf_mbox_recovery_work. However,
enic_mbox_vf_kick_recovery() only schedules that work while
netif_running() is true, and that fails on each of these paths:

__dev_close_many() clears __LINK_STATE_START before it calls ndo_stop.
A rejected DELETE from __enic_stop() therefore schedules nothing.

On a failed enic_open(), the core clears __LINK_STATE_START before it
drops RTNL. A queued recovery worker then sees the interface down in
enic_hang_reset() and returns.

After a runtime MAC change takes the replace path, enic_remove()
cancels any pending recovery worker with disable_work_sync().

If the device is removed afterwards, enic_remove() still sees
vf_registered and calls enic_mbox_vf_unregister(). But
enic_mbox_send_msg_id() finds mbox_send_disabled set and fails
locally with -ENODEV, so VF_UNREGISTER never reaches the PF.

The commit message and the new comment in enic_remove() make
VF_UNREGISTER the cleanup boundary that removes the VF-requested
station address. In this sequence the PF keeps the VF registered after
the driver is gone. It also keeps the station filter that the recovery
request was meant to clean up.

Should enic_remove() still be able to send VF_UNREGISTER when the
channel is healthy and only a reconnect was requested? Or should a
stopped device get re-registered some other way?

[ ... ]

> +	changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> +	enic_vf_station_sync_reset(enic);
> +	if (changed)
> +		dev_addr_set_sync(enic->netdev, selected);
> +	if (changed || (!zero_policy &&
> +			enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
> +		enic->netdev->addr_assign_type = zero_policy ?
> +			NET_ADDR_RANDOM : NET_ADDR_SET;
> +	ether_addr_copy(enic->mac_addr, selected);
> +	if (station_installed)
> +		enic_vf_station_addr_set(enic, selected);
> +	enic_vf_station_sync_reset(enic);

[ ... ]

> @@ -1064,6 +1067,512 @@ static int enic_set_mac_addr(struct net_device *netdev, char *addr)
>  	return 0;
>  }
>  
> +static void enic_vf_station_recovery_required(struct enic *enic)
> +{
> +	enic_mbox_vf_require_reconnect(enic);
> +}
> +
> +static void enic_vf_station_addr_set(struct enic *enic, const u8 *addr)
> +{
> +	ether_addr_copy(enic->vf_station_addr, addr);
> +	enic->vf_station_addr_valid = true;
> +}
> +
> +static int enic_vf_keep_nonstation_sync(struct net_device *netdev,
> +					const u8 *addr)
> +{
> +	struct enic *enic = netdev_priv(netdev);
> +
> +	if (!ether_addr_equal(addr, enic->vf_station_addr))
> +		return -ENOENT;
> +	if (WARN_ON_ONCE(!enic->uc_count))
> +		return 0;
> +	enic->uc_count--;
> +
> +	return 0;
> +}
> +
> +static void enic_vf_station_sync_reset(struct enic *enic)
> +{
> +	if (!enic->vf_station_addr_valid)
> +		return;
> +
> +	/* The PF keys its MAC ledger by address. A station entry is also the
> +	 * receive filter for that address and must not retain a second core
> +	 * synchronization reference which could later delete the station.
> +	 */
> +	netif_addr_lock_bh(enic->netdev);
> +	__dev_uc_unsync(enic->netdev, enic_vf_keep_nonstation_sync);
> +	netif_addr_unlock_bh(enic->netdev);
> +}
> +
> +static int enic_vf_station_addr_del(struct enic *enic)
> +{
> +	int err;
> +
> +	if (!enic->vf_station_addr_valid)
> +		return 0;
> +
> +	err = enic_mbox_vf_add_del_mac(enic, enic->vf_station_addr,
> +				       false, true);
> +	if (!err) {
> +		enic->vf_station_addr_valid = false;
> +	} else if (READ_ONCE(enic->mbox_tx_poisoned)) {
> +		enic_mbox_vf_link_state_set_running(enic, false);
> +	} else if (err == -EACCES) {
> +		/* A definitive rejected DELETE leaves an unrequested station
> +		 * filter installed. Fresh registration is the cleanup boundary.
> +		 */
> +		enic_vf_station_recovery_required(enic);
> +	}
> +
> +	return err;
> +}
> +
> +/* End every replacement with an equal-address DEL+ADD pair. A bare ADD could
> + * report DUPLICATE for a secondary exact filter without applying the current
> + * station-address policy. If another station is tracked, delete it first in
> + * the same compound request.
> + */
> +static int enic_vf_station_addr_replace(struct enic *enic, const u8 *addr,
> +					bool *policy_rejected)
> +{
> +	struct enic_mac_addr macs[3] = {};
> +	bool all_deletes_skipped = true;
> +	bool deletes_converged = true;
> +	u16 num_macs = 0;
> +	unsigned int i;
> +	u16 result;
> +	int err;
> +
> +	if (policy_rejected)
> +		*policy_rejected = false;
> +
> +	if (enic->vf_station_addr_valid &&
> +	    !ether_addr_equal(enic->vf_station_addr, addr)) {
> +		ether_addr_copy(macs[num_macs].addr, enic->vf_station_addr);
> +		macs[num_macs++].flags =
> +			cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
> +	}
> +	ether_addr_copy(macs[num_macs].addr, addr);
> +	macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
> +	ether_addr_copy(macs[num_macs].addr, addr);
> +	macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_ADD |
> +					    ENIC_MAC_ADDR_FLAG_STATION);
> +
> +	err = enic_mbox_vf_add_del_macs(enic, macs, num_macs);
> +	if (err) {
> +		if (READ_ONCE(enic->mbox_tx_poisoned))
> +			enic_mbox_vf_link_state_set_running(enic, false);
> +		return err;
> +	}
> +
> +	for (i = 0; i < num_macs - 1; i++) {
> +		result = le16_to_cpu(macs[i].flags) &
> +			 ENIC_MAC_ADDR_FLAG_REPLY_MASK;
> +		if (result != ENIC_MAC_ADDR_FLAG_SKIPPED)
> +			all_deletes_skipped = false;
> +		if (result && result != ENIC_MAC_ADDR_FLAG_NOT_FOUND)
> +			deletes_converged = false;
> +	}
> +	result = le16_to_cpu(macs[num_macs - 1].flags) &
> +		 ENIC_MAC_ADDR_FLAG_REPLY_MASK;
> +	if (deletes_converged && !result)
> +		return 0;
> +
> +	/* A policy-rejected ADD can be reported with all preceding DELETEs
> +	 * skipped. No operation changed state in that coherent result tuple.
> +	 */
> +	if (all_deletes_skipped && result) {
> +		if (policy_rejected)
> +			*policy_rejected =
> +				result == ENIC_MAC_ADDR_FLAG_NOT_PERMITTED;
> +		if (result & (ENIC_MAC_ADDR_FLAG_DUPLICATE |
> +			      ENIC_MAC_ADDR_FLAG_PERMANENT_MASK))
> +			return -EACCES;
> +		return -EIO;
> +	}
> +
> +	/* After any other partial or contradictory result, the VF does not know
> +	 * which station address the PF kept. Re-register before accepting traffic.
> +	 */
> +	enic_vf_station_recovery_required(enic);
> +	for (i = 0; i < num_macs; i++)
> +		if (le16_to_cpu(macs[i].flags) &
> +		    ENIC_MAC_ADDR_FLAG_PERMANENT_MASK)
> +			return -EACCES;
> +
> +	return -EIO;
> +}
> +
> +static void enic_vf_admin_mac_cache_selected(struct enic *enic,
> +					     const u8 *addr)
> +{
> +	/* A zero administrative policy delegates the operational address to
> +	 * the VF. Preserve a successful user selection across reconnects.
> +	 */
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	if (is_zero_ether_addr(enic->vf_admin_mac)) {
> +		ether_addr_copy(enic->vf_admin_mac_random_addr, addr);
> +		enic->vf_admin_mac_random_valid = true;
> +	}
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +static void enic_vf_admin_mac_work(struct work_struct *work)
> +{
> +	struct enic *enic = container_of(to_delayed_work(work), struct enic,
> +					 vf_admin_mac_work);
> +	u8 policy[ETH_ALEN] __aligned(2);
> +	u8 selected[ETH_ALEN] __aligned(2);
> +	unsigned long delay = 0;
> +	u32 generation = 0;
> +	bool changed;
> +	bool mutated = false;
> +	bool reschedule = false;
> +	bool station_installed = false;
> +	bool stale = false;
> +	bool zero_policy;
> +	bool pending;
> +	int err = 0;
> +
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	pending = enic->vf_admin_mac_pending &&
> +		enic->vf_admin_mac_work_enabled;
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +	if (!pending)
> +		return;
> +
> +	/* Teardown owns RTNL while synchronously cancelling this work. Do not
> +	 * block that owner.
> +	 */
> +	if (!rtnl_trylock()) {
> +		spin_lock_bh(&enic->vf_admin_mac_lock);
> +		if (enic->vf_admin_mac_pending &&
> +		    enic->vf_admin_mac_work_enabled)
> +			mod_delayed_work(system_percpu_wq,
> +					 &enic->vf_admin_mac_work,
> +					 msecs_to_jiffies(10));
> +		spin_unlock_bh(&enic->vf_admin_mac_lock);
> +		return;
> +	}
> +
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	pending = enic->vf_admin_mac_pending &&
> +		enic->vf_admin_mac_work_enabled;
> +	if (pending) {
> +		ether_addr_copy(policy, enic->vf_admin_mac);

[Severity: Low]
vf_station_addr and the on-stack MAC buffers get __aligned(2). The
reason is that ether_addr_copy(), ether_addr_equal() and
is_zero_ether_addr() use 16-bit accesses when
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is not set.

vf_admin_mac and vf_admin_mac_random_addr are passed to the same
helpers but carry no alignment annotation. The callers are
enic_vf_admin_mac_work(), enic_vf_admin_mac_notify(),
enic_vf_admin_mac_refresh() and enic_set_mac_address_dynamic().

Both arrays directly follow vf_admin_mac_lock. On configurations where
spinlock_t is one byte, they land at odd offsets in struct enic. One
example is sparc32 SMP without lock debugging, where arch_spinlock_t
is a single volatile unsigned char. The helpers would then take
alignment traps.

The existing mac_addr after devcmd_lock has the same layout problem.
This patch now writes it with ether_addr_copy() in
enic_vf_admin_mac_work() and enic_vf_admin_mac_refresh().

ENIC only depends on PCI, so it builds on such configurations, even if
real VIC adapters are unlikely to appear there. Could these arrays get
__aligned(2) as well, to match vf_station_addr?

> +		generation = enic->vf_admin_mac_generation;
> +		zero_policy = is_zero_ether_addr(policy);
> +		if (zero_policy && enic->vf_admin_mac_random_valid)
> +			ether_addr_copy(selected,
> +					enic->vf_admin_mac_random_addr);
> +	}
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +	if (!pending)
> +		goto unlock;
> +
> +	if (zero_policy && !READ_ONCE(enic->vf_admin_mac_random_valid)) {
> +		eth_random_addr(selected);
> +		spin_lock_bh(&enic->vf_admin_mac_lock);
> +		if (!enic->vf_admin_mac_pending ||
> +		    !enic->vf_admin_mac_work_enabled ||
> +		    enic->vf_admin_mac_generation != generation ||
> +		    !is_zero_ether_addr(enic->vf_admin_mac)) {
> +			stale = true;
> +		} else if (enic->vf_admin_mac_random_valid) {
> +			ether_addr_copy(selected,
> +					enic->vf_admin_mac_random_addr);
> +		} else {
> +			ether_addr_copy(enic->vf_admin_mac_random_addr, selected);
> +			enic->vf_admin_mac_random_valid = true;
> +		}
> +		spin_unlock_bh(&enic->vf_admin_mac_lock);
> +		if (stale)
> +			goto unlock;
> +	} else if (!zero_policy) {
> +		ether_addr_copy(selected, policy);
> +	}
> +
> +	if (!netif_device_present(enic->netdev) ||

[Severity: Medium]
Is a detached netdev really a retryable condition here? This driver
never calls netif_device_attach() after enic_remove() or
enic_detach_after_recovery_failure() has detached the device. Yet this
check reports it as -EAGAIN.

The retry logic after the unlock label treats that like any other
failure. It reschedules up to ENIC_VF_ADMIN_MAC_MAX_RETRIES times, then
calls enic_vf_station_recovery_required(). That sets
mbox_send_disabled through enic_mbox_vf_mark_reconnect_locked() while
vf_registered stays true. Recovery cannot do anything for a detached
device.

I see two ways to get here.

First, enic_detach_after_recovery_failure() from enic_open() or
__enic_stop() leaves the device detached. The admin channel stays
live, vf_registered stays true and vf_admin_mac_work_enabled is still
true. Any later PF admin MAC notification then walks through the
retries and disables mailbox sends.

Second, enic_remove() drops RTNL after netif_device_detach() and only
later calls enic_vf_admin_mac_quiesce(). A worker that has already
used up its retries can run in that window and reach the recovery
call.

In both cases the later enic_mbox_vf_unregister() in enic_remove()
fails with -ENODEV inside enic_mbox_send_msg_id(). The PF never gets
VF_UNREGISTER and keeps the VF registration and station filter after
removal.

Should a non-present device just leave the update pending, without
counting it as a retry or triggering recovery? And could enic_remove()
quiesce the admin MAC worker before it releases RTNL after detaching?
The worker only uses rtnl_trylock(), so that should not deadlock.

> +	    !READ_ONCE(enic->vf_registered)) {
> +		err = -EAGAIN;
> +		goto unlock;
> +	}
> +
> +	/* A nonzero notification describes a station address the PF has already
> +	 * installed. Zero delegates selection to the VF, which registers the
> +	 * selected random address through the policy-safe replacement request.
> +	 */
> +	if (!READ_ONCE(enic->datapath_open)) {
> +		station_installed = !zero_policy &&
> +			(!enic->vf_station_addr_valid ||
> +			 ether_addr_equal(enic->vf_station_addr, selected));
> +	} else if (zero_policy) {
> +		mutated = true;
> +		err = enic_vf_station_addr_replace(enic, selected, NULL);
> +		station_installed = !err;
> +	} else if (enic->vf_station_addr_valid &&
> +		   !ether_addr_equal(enic->vf_station_addr, selected)) {
> +		mutated = true;
> +		err = enic_vf_station_addr_del(enic);
> +		station_installed = !err;
> +	} else {
> +		station_installed = true;
> +	}
> +	if (err)
> +		goto unlock;
> +
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	if (!enic->vf_admin_mac_pending ||
> +	    !enic->vf_admin_mac_work_enabled ||
> +	    enic->vf_admin_mac_generation != generation) {
> +		stale = true;
> +		/* If policy changed while the request was running, the completed
> +		 * station change may no longer match it. Record recovery while holding
> +		 * vf_admin_mac_lock, which also protects VF worker shutdown. Teardown
> +		 * therefore either suppresses the update or sees it first, and already
> +		 * uses unregister/register to clear old state.
> +		 */
> +		if (mutated && enic->vf_admin_mac_work_enabled)
> +			enic_vf_station_recovery_required(enic);
> +	} else {
> +		enic->vf_admin_mac_pending = false;
> +		enic->vf_admin_mac_retries = 0;
> +		enic->vf_admin_mac_recovery_attempted = false;
> +		if (!zero_policy)
> +			enic->vf_admin_mac_random_valid = false;
> +	}
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +	if (stale)
> +		goto unlock;
> +
> +	changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> +	enic_vf_station_sync_reset(enic);
> +	if (changed)
> +		dev_addr_set_sync(enic->netdev, selected);
> +	if (changed || (!zero_policy &&
> +			enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
> +		enic->netdev->addr_assign_type = zero_policy ?
> +			NET_ADDR_RANDOM : NET_ADDR_SET;
> +	ether_addr_copy(enic->mac_addr, selected);
> +	if (station_installed)
> +		enic_vf_station_addr_set(enic, selected);
> +	enic_vf_station_sync_reset(enic);
> +	if (enic->netdev->reg_state == NETREG_REGISTERED) {
> +		if (changed)
> +			call_netdevice_notifiers(NETDEV_CHANGEADDR,
> +						 enic->netdev);
> +		netif_rx_mode_schedule_update(enic->netdev);
> +	}
> +	netdev_info(enic->netdev, "MBOX: admin MAC set to %pM\n", selected);
> +
> +unlock:
> +	rtnl_unlock();
> +
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	if (err && enic->vf_admin_mac_pending &&
> +	    enic->vf_admin_mac_work_enabled &&
> +	    generation == enic->vf_admin_mac_generation &&
> +	    !READ_ONCE(enic->mbox_send_disabled)) {
> +		if (enic->vf_admin_mac_retries <
> +		    ENIC_VF_ADMIN_MAC_MAX_RETRIES) {
> +			enic->vf_admin_mac_retries++;
> +			reschedule = true;
> +			delay = msecs_to_jiffies(ENIC_VF_ADMIN_MAC_RETRY_MS);
> +		} else if (!enic->vf_admin_mac_recovery_attempted) {
> +			enic->vf_admin_mac_recovery_attempted = true;
> +			/* vf_admin_mac_lock also protects VF worker shutdown. */
> +			enic_vf_station_recovery_required(enic);
> +		}
> +	}
> +	if (enic->vf_admin_mac_pending &&
> +	    enic->vf_admin_mac_work_enabled &&
> +	    generation != enic->vf_admin_mac_generation) {
> +		reschedule = true;
> +		delay = 0;
> +	}
> +	if (enic->vf_admin_mac_pending && reschedule)
> +		mod_delayed_work(system_percpu_wq,
> +				 &enic->vf_admin_mac_work, delay);
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +void enic_vf_admin_mac_notify(struct enic *enic, const u8 *addr)
> +{
> +	bool new_policy;
> +
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	new_policy = !enic->vf_admin_mac_pending ||
> +		!ether_addr_equal(enic->vf_admin_mac, addr);
> +	if (new_policy) {
> +		ether_addr_copy(enic->vf_admin_mac, addr);
> +		if (!is_zero_ether_addr(addr))
> +			enic->vf_admin_mac_random_valid = false;
> +		enic->vf_admin_mac_pending = true;
> +		enic->vf_admin_mac_generation++;
> +		enic->vf_admin_mac_retries = 0;
> +		enic->vf_admin_mac_recovery_attempted = false;
> +	}
> +	if (new_policy && enic->vf_admin_mac_work_enabled)
> +		mod_delayed_work(system_percpu_wq,
> +				 &enic->vf_admin_mac_work, 0);
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +void enic_vf_admin_mac_quiesce(struct enic *enic)
> +{
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	enic->vf_admin_mac_work_enabled = false;
> +	enic->vf_admin_mac_generation++;
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +	cancel_delayed_work_sync(&enic->vf_admin_mac_work);
> +}
> +
> +void enic_vf_admin_mac_rearm(struct enic *enic)
> +{
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	enic->vf_admin_mac_work_enabled = true;
> +	if (enic->vf_admin_mac_pending)
> +		mod_delayed_work(system_percpu_wq,
> +				 &enic->vf_admin_mac_work, 0);
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +void enic_vf_admin_mac_purge(struct enic *enic)
> +{
> +	enic_vf_admin_mac_quiesce(enic);
> +	spin_lock_bh(&enic->vf_admin_mac_lock);
> +	enic->vf_admin_mac_pending = false;
> +	enic->vf_admin_mac_random_valid = false;
> +	enic->vf_admin_mac_recovery_attempted = false;
> +	enic->vf_admin_mac_retries = 0;
> +	enic->vf_admin_mac_generation++;
> +	spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +/* CMD_GET_MAC_ADDR is the PF-owned policy store. Re-read it after REGISTER so
> + * a lost notification cannot leave the VF using stale administrative policy.
> + */
> +static int enic_vf_admin_mac_refresh(struct enic *enic)
> +{
> +	u8 previous_policy[ETH_ALEN] __aligned(2);
> +	u8 random_addr[ETH_ALEN] __aligned(2);
> +	u8 selected[ETH_ALEN] __aligned(2);
> +	u8 policy[ETH_ALEN] __aligned(2);
> +	u32 generation;
> +	bool apply_policy;
> +	bool changed;
> +	bool pending;
> +	bool policy_changed;
> +	bool zero_policy;
> +	unsigned int attempt;
> +	int err;
> +
> +	for (attempt = 0; attempt < ENIC_VF_ADMIN_MAC_REFRESH_RETRIES;
> +	     attempt++) {
> +		spin_lock_bh(&enic->vf_admin_mac_lock);
> +		generation = enic->vf_admin_mac_generation;
> +		pending = enic->vf_admin_mac_pending;
> +		ether_addr_copy(previous_policy, enic->vf_admin_mac);
> +		spin_unlock_bh(&enic->vf_admin_mac_lock);
> +
> +		err = enic_dev_get_mac_addr(enic, policy);
> +		if (err)
> +			return err;
> +		if (is_multicast_ether_addr(policy))
> +			return -EADDRNOTAVAIL;
> +
> +		zero_policy = is_zero_ether_addr(policy);
> +		if (zero_policy)
> +			eth_random_addr(random_addr);
> +
> +		spin_lock_bh(&enic->vf_admin_mac_lock);
> +		if (enic->vf_admin_mac_generation != generation) {
> +			spin_unlock_bh(&enic->vf_admin_mac_lock);
> +			continue;
> +		}
> +
> +		policy_changed = !ether_addr_equal(previous_policy, policy);
> +		apply_policy = pending || policy_changed ||
> +			!is_valid_ether_addr(enic->netdev->dev_addr) ||
> +			(!zero_policy &&
> +			 !ether_addr_equal(enic->netdev->dev_addr, policy));
> +		if (!apply_policy) {
> +			ether_addr_copy(selected, enic->netdev->dev_addr);
> +			if (zero_policy) {
> +				ether_addr_copy(enic->vf_admin_mac_random_addr,
> +						selected);
> +				enic->vf_admin_mac_random_valid = true;
> +			}
> +		} else if (zero_policy && enic->vf_admin_mac_random_valid) {
> +			ether_addr_copy(selected,
> +					enic->vf_admin_mac_random_addr);
> +		} else if (zero_policy) {
> +			ether_addr_copy(selected, random_addr);
> +			ether_addr_copy(enic->vf_admin_mac_random_addr, selected);
> +			enic->vf_admin_mac_random_valid = true;
> +		} else {
> +			ether_addr_copy(selected, policy);
> +			enic->vf_admin_mac_random_valid = false;
> +		}
> +		ether_addr_copy(enic->vf_admin_mac, policy);
> +		enic->vf_admin_mac_pending = false;
> +		enic->vf_admin_mac_recovery_attempted = false;
> +		enic->vf_admin_mac_retries = 0;
> +		enic->vf_admin_mac_generation++;
> +		spin_unlock_bh(&enic->vf_admin_mac_lock);
> +
> +		changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> +		if (changed) {
> +			if (enic->netdev->reg_state == NETREG_REGISTERED)
> +				dev_addr_set_sync(enic->netdev, selected);
> +			else
> +				eth_hw_addr_set(enic->netdev, selected);
> +		}
> +		if (zero_policy && changed)
> +			enic->netdev->addr_assign_type = NET_ADDR_RANDOM;
> +		else if (!zero_policy &&
> +			 enic->netdev->reg_state == NETREG_REGISTERED &&
> +			 (changed ||
> +			  enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
> +			enic->netdev->addr_assign_type = NET_ADDR_SET;
> +		ether_addr_copy(enic->mac_addr, selected);
> +		if (changed && enic->netdev->reg_state == NETREG_REGISTERED)
> +			call_netdevice_notifiers(NETDEV_CHANGEADDR,
> +						 enic->netdev);
> +
> +		return 0;
> +	}
> +
> +	return -EAGAIN;
> +}
> +
> +static int enic_vf_station_addr_open(struct enic *enic)
> +{
> +	struct net_device *netdev = enic->netdev;
> +	u8 requested[ETH_ALEN] __aligned(2);
> +	bool policy_rejected;
> +	int err;
> +
> +	ether_addr_copy(requested, netdev->dev_addr);
> +	err = enic_vf_station_addr_replace(enic, requested, &policy_rejected);
> +	if (!policy_rejected || !READ_ONCE(enic->vf_registered) ||
> +	    READ_ONCE(enic->mbox_send_disabled))
> +		return err;
> +
> +	/* PF policy can change after the last refresh, with its notification
> +	 * still in flight. A clean rejection permits one attempt at the new MAC.
> +	 */
> +	err = enic_vf_admin_mac_refresh(enic);
> +	if (err)
> +		return err;
> +	if (ether_addr_equal(requested, netdev->dev_addr))
> +		return -EACCES;
> +
> +	return enic_vf_station_addr_replace(enic, netdev->dev_addr, NULL);
> +}
> +
>  static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
>  {
>  	struct enic *enic = netdev_priv(netdev);

[Severity: Low]
enic_vf_admin_mac_notify() runs from admin_msg_work without RTNL. It
updates vf_admin_mac_pending and vf_admin_mac_random_valid with plain
stores under vf_admin_mac_lock. The other writers of these flags are
also plain stores under the same lock: enic_vf_admin_mac_refresh(),
enic_vf_admin_mac_purge(), enic_vf_admin_mac_cache_selected() and the
worker itself.

Here the worker reads vf_admin_mac_random_valid with READ_ONCE() just
after dropping vf_admin_mac_lock. enic_open() likewise reads
vf_admin_mac_pending with READ_ONCE() without taking the lock. A
READ_ONCE() racing with an unmarked store is still a data race under
the memory model. KCSAN will report it whenever a PF notification
arrives during open or while the worker runs.

I don't see a functional failure. The worker revalidates under
vf_admin_mac_lock, and open falls back to the policy-rejected retry in
enic_vf_station_addr_open(). But the marking suggests a lockless
protocol that the writers do not follow.

The worker already holds vf_admin_mac_lock a few lines earlier, when
it copies policy and generation. Could it capture random_valid into a
local there? And could enic_open() take vf_admin_mac_lock for the
pending check? Otherwise the writers would need WRITE_ONCE() so the
lockless reads are properly paired.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-enic-sriov-v2-vf-receive-control-v6-0-ca38950bbe07%40cisco.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH net-next v6 7/7] enic: configure V2 VF receive mode over mailbox
  2026-12-04 15:29 ` [PATCH net-next v6 7/7] enic: configure V2 VF receive mode over mailbox Satish Kharat
@ 2026-12-05 16:28   ` netdev-bot+sashiko
  0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 16:28 UTC (permalink / raw)
  To: satishkh
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
	netdev, linux-kernel, sebaddel, aradhana, rfaucett, sdf

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] On V2 VFs, a group-bit (link-local) address in dev->uc is
  never programmed and nothing falls back to cover it.
- [Medium] An address the PF permanently rejects on ADD keeps taking a
  projected exact-filter slot on every later callback, so a valid…
- [Low] enic_set_vf_rx_mode() reports the same packet-filter denial more
  than once per callback.

--

enic: configure V2 VF receive mode over mailbox

This patch adds an asynchronous receive-mode callback for V2 VFs. The
callback sends unicast and multicast exact-filter changes, plus
packet-filter settings, to the PF over the mailbox. It orders broad-mode
transitions around exact-filter updates, reserves 31 unicast and 32
multicast slots, and skips three kinds of address: the station address,
all-zero MACs, and addresses whose group bit does not match their list.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 0ee2ea5b24682..116666be60340 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c

[ ... ]

> @@ -1664,17 +1666,425 @@ static int enic_set_mac_address(struct net_device *netdev, void *p)

[ ... ]

> +static bool
> +enic_vf_secondary_addr_valid(const struct enic *enic,
> +			     const struct netdev_hw_addr *ha)
> +{
> +	u8 type = is_multicast_ether_addr(ha->addr) ?
> +		  NETDEV_HW_ADDR_T_MULTICAST : NETDEV_HW_ADDR_T_UNICAST;
> +
> +	/* The PF stores one exact filter per MAC. Admit it from the list
> +	 * matching its Ethernet address class, and leave the station separate.
> +	 */
> +	return ha->type == type && !is_zero_ether_addr(ha->addr) &&
> +	       !(enic->vf_station_addr_valid &&
> +		 ether_addr_equal(ha->addr, enic->vf_station_addr));
> +}

[Severity: Medium]
Can a link-local group address in dev->uc be silently dropped here?

The core puts these addresses into the uc list itself.
enic_netdev_vf_v2_ops has no ndo_fdb_add, so the fdb add path goes
through ndo_dflt_fdb_add():

net/core/rtnetlink.c:ndo_dflt_fdb_add() {
    ...
	if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
		err = dev_uc_add_excl(dev, addr);
    ...
}

dev_uc_add_excl() stores the entry as NETDEV_HW_ADDR_T_UNICAST, and the
snapshot passed to ndo_set_rx_mode_async keeps ha->type. So a command
like "bridge fdb add 01:80:c2:00:00:0e dev <vf> self permanent"
succeeds. enic_vf_secondary_addr_valid() then rejects the entry, because
is_multicast_ether_addr() is true while ha->type is T_UNICAST.

The same predicate gates enic_vf_addr_list_count() and
enic_vf_collect_mac_ops(). As a result, no add operation is issued for
the address, and it does not count toward CMD_PFILTER_PROMISCUOUS or
CMD_PFILTER_ALL_MULTICAST. IFF_UNICAST_FLT is set, so the core does not
fall back to uc_promisc either.

enic_set_vf_rx_mode() returns 0 and the core treats the update as
converged. The LLDP/STP style frames that were requested are then never
received. An upper device that syncs its uc list down to the VF could
reach the same state.

The commit message gives this reason for the class check:

    Counting the same MAC in both lists can
    reserve capacity twice and removing one reference can delete the filter
    while the other list still considers it synchronized.

Could that be handled by classifying entries by their address bit and
deduplicating across the two lists, instead of dropping cross-class
entries entirely?

[ ... ]

> +	for (i = 0; i < num_ops; i++) {
> +		u16 flags = le16_to_cpu(macs[i].flags);
> +		bool add = flags & ENIC_MAC_ADDR_FLAG_ADD;
> +

[ ... ]

> +		if (flags & ENIC_MAC_ADDR_FLAG_PERMANENT_MASK) {
> +			if (add)
> +				permanent_add = true;
> +			else
> +				reconnect = true;
> +			continue;
> +		}

[Severity: Medium]
Does a permanently denied add keep taking a projected exact-filter slot
on every later callback?

After the denial, the entry keeps sync_cnt == 0, enic->uc_count and
enic->mc_count are unchanged, and enic_set_vf_rx_mode() turns the
resulting -EACCES into success:

	err = enic_vf_sync_mac_filters(enic, uc, mc);
	if (err == -EACCES) {
		...
		err = 0;
	}

On the next callback, projected_uc restarts from enic->uc_count.
enic_vf_collect_mac_ops() then collects the same unsynced entry again,
because its add branch only skips on:

	if (ha->sync_cnt || *projected_count >= max_filters)
		continue;

For example, take a uc list with PF-denied A followed by valid B1..B31:

  pass 1:  collects A and B1..B30 (limit 31), A is denied,
           uc_count becomes 30
  pass 2+: projected starts at 30, A takes slot 31, B31 is never
           collected

CMD_PFILTER_PROMISCUOUS is requested because 32 > 31. If the PF refuses
it, B31 is never received, even though 30 secondaries plus the station
leave one of the PF's 32 entries free. Each extra denied address costs
another slot. Multicast behaves the same way when ALL_MULTICAST is
denied.

The commit message already avoids this crowd-out for the all-zero MAC:

    The PF rejects that address as
    INVALID, so reserving capacity for it would crowd out a later valid
    address on every update.

Should addresses the PF has permanently denied also be left out of the
projection?

[ ... ]

> +	if (broad_enable_needed) {

[ ... ]

> +		target_filter_updated = prefilter_flags == flags;
> +		enic_vf_report_pkt_filter_denial(netdev, flags, applied_flags);
> +	}
> +
> +	if (broad_withdrawal) {

[ ... ]

> +		target_filter_updated = true;
> +		enic_vf_report_pkt_filter_denial(netdev, flags, applied_flags);
> +	}

[ ... ]

> +	if (!target_filter_updated && filter_needed) {
> +		err = enic_vf_set_pkt_filter(enic, flags, &applied_flags);
> +		if (err)
> +			return err;
> +	} else if (!target_filter_updated) {
> +		applied_flags = enic->vf_pkt_filter_applied;
> +	}
> +
> +	enic_vf_report_pkt_filter_denial(netdev, flags, applied_flags);

[Severity: Low]
Is the same denial reported more than once per callback here?

When broad_enable_needed is true and broad_withdrawal is false,
prefilter_flags == flags, so the enable branch reports the denial.
Neither of the final if/else-if branches runs, and this call reports it
again with the same arguments. A combined enable-plus-withdrawal
transition reports it three times.

A denied broad mode keeps broad_enable_needed true on every callback.
So each address-list update prints the same netdev_dbg lines two or
three times.

Would keeping only this final report be enough?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-enic-sriov-v2-vf-receive-control-v6-0-ca38950bbe07%40cisco.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-12-05 16:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 15:29 [PATCH net-next v6 0/7] enic: add V2 VF receive control over MBOX Satish Kharat
2026-12-04 15:29 ` [PATCH net-next v6 1/7] net: add netif_rx_mode_schedule_update() Satish Kharat
2026-12-04 15:29 ` [PATCH net-next v6 2/7] enic: serialize V2 VF mailbox requests Satish Kharat
2026-12-04 15:29 ` [PATCH net-next v6 3/7] enic: recover V2 VF mailbox after request failure Satish Kharat
2026-12-05 16:28   ` netdev-bot+sashiko
2026-12-04 15:29 ` [PATCH net-next v6 4/7] enic: validate V2 VF configuration replies Satish Kharat
2026-12-05 16:28   ` netdev-bot+sashiko
2026-12-04 15:29 ` [PATCH net-next v6 5/7] net: add dev_addr_set_sync() for driver address updates Satish Kharat
2026-12-05 16:28   ` netdev-bot+sashiko
2026-12-04 15:29 ` [PATCH net-next v6 6/7] enic: manage V2 VF station and administrative MAC Satish Kharat
2026-12-05 16:28   ` netdev-bot+sashiko
2026-12-04 15:29 ` [PATCH net-next v6 7/7] enic: configure V2 VF receive mode over mailbox Satish Kharat
2026-12-05 16:28   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox