* [PATCH net-next v3 1/6] net: add netif_rx_mode_schedule_update()
2026-11-18 23:32 [PATCH net-next v3 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
@ 2026-11-18 23:32 ` Satish Kharat
2026-11-23 0:32 ` netdev-bot+sashiko
2026-11-18 23:32 ` [PATCH net-next v3 2/6] enic: serialize V2 VF mailbox requests Satish Kharat
` (4 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Satish Kharat @ 2026-11-18 23:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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.
Assisted-by: LLM
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 0325c6f2a7d1..4ff3523f9474 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -5232,6 +5232,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] 12+ messages in thread* Re: [PATCH net-next v3 1/6] net: add netif_rx_mode_schedule_update()
2026-11-18 23:32 ` [PATCH net-next v3 1/6] net: add netif_rx_mode_schedule_update() Satish Kharat
@ 2026-11-23 0:32 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 0:32 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, netdev,
linux-kernel, sebaddel, aradhana, rfaucett
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: netif_rx_mode_schedule_update() is exported with
EXPORT_SYMBOL_GPL and declared in include/linux/netdevice.h, but…
--
net: add netif_rx_mode_schedule_update()
This adds an exported helper that callers use to start a new receive-mode
update after a state transition. It cancels any pending retry timer and
resets the retry backoff, then queues an immediate update. Address-list
sync state is left as it is.
> diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
> index b6f25e487984b..89ae77360a0bb 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);
> }
>
[ ... ]
> +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);
[Severity: Low]
This isn't a bug, but nothing in the tree calls
netif_rx_mode_schedule_update() at this commit. It is still exported
with EXPORT_SYMBOL_GPL and declared in include/linux/netdevice.h.
Later patches in the series add the callers in
drivers/net/ethernet/cisco/enic/enic_main.c:
- the admin MAC notification
- the V2 VF set-MAC path
- the reopen in _enic_change_mtu()
- the soft-reset reopen
- the hang-reset reopen
enic can be built as a module, so the GPL export and the public
declaration both look right. The existing retry users in bnxt_init_chip()
and bnge are not converted, but the commit message does not say they
will be.
Would it be cleaner to fold this helper into the first enic patch that
uses it? Or could the commit message name the upcoming user, so the
export does not look orphaned when this patch is read on its own?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-b4-enic-sriov-v2-vf-receive-control-v3-0-2cb25677aa8c%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next v3 2/6] enic: serialize V2 VF mailbox requests
2026-11-18 23:32 [PATCH net-next v3 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
2026-11-18 23:32 ` [PATCH net-next v3 1/6] net: add netif_rx_mode_schedule_update() Satish Kharat
@ 2026-11-18 23:32 ` Satish Kharat
2026-11-18 23:32 ` [PATCH net-next v3 3/6] enic: recover V2 VF mailbox after request failure Satish Kharat
` (3 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Satish Kharat @ 2026-11-18 23:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
The VF stores one expected reply and uses one completion for mailbox
requests. If two VF control paths issue requests at the same time, the
second request can replace the reply state for the first.
Add a request mutex used only by the VF. Hold it from before a request is
armed until its reply or timeout has been consumed. Recheck VF registration
after taking the mutex and clear pending state on send failure so a later
request cannot inherit it.
PF-side request processing is unchanged. Unsolicited PF notifications and
their acknowledgments remain asynchronous.
Assisted-by: LLM
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
drivers/net/ethernet/cisco/enic/enic.h | 1 +
drivers/net/ethernet/cisco/enic/enic_mbox.c | 49 +++++++++++++++++++++++++++--
2 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index a4f9f58c1adf..15f17019c076 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -344,6 +344,7 @@ struct enic {
* 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] 12+ messages in thread* [PATCH net-next v3 3/6] enic: recover V2 VF mailbox after request failure
2026-11-18 23:32 [PATCH net-next v3 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
2026-11-18 23:32 ` [PATCH net-next v3 1/6] net: add netif_rx_mode_schedule_update() Satish Kharat
2026-11-18 23:32 ` [PATCH net-next v3 2/6] enic: serialize V2 VF mailbox requests Satish Kharat
@ 2026-11-18 23:32 ` Satish Kharat
2026-11-23 0:32 ` netdev-bot+sashiko
2026-11-18 23:32 ` [PATCH net-next v3 4/6] enic: validate V2 VF configuration replies Satish Kharat
` (2 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Satish Kharat @ 2026-11-18 23:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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.
Use the hang-reset worker for V2 VF recovery. Deployed async PFs permit
the hang-reset pair for VFs but deny soft reset and its capability query.
Issue the known V2 pair directly. Keep other ENIC functions' capability
and fallback behavior, with INIT deferred until soft reset completes.
Skip HANG_NOTIFY for mailbox recovery because it reports an actual Tx hang.
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. Keep recovery bounded by
the fault generation, allowing a follow-up only after committed success.
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.
Keep VF receive traffic stopped during registration and initial open.
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.
Assisted-by: LLM
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
drivers/net/ethernet/cisco/enic/enic.h | 25 ++
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 | 567 +++++++++++++++++++++----
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, 750 insertions(+), 104 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 15f17019c076..22a0ff71a43c 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -314,6 +314,27 @@ 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;
+ /* Suppress self-requeue while a reset worker is already attempting the
+ * reconnect. The fault generation records a fault arriving during recovery
+ * so one later generation is not lost. A failed handshake remains
+ * quarantined until a later external recovery event or close/open.
+ */
+ bool vf_mbox_recovery_active;
+ 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];
@@ -346,6 +367,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..e6232927af80 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,27 @@ static void enic_notify_timer_start(struct enic *enic)
}
}
-/* rtnl lock is held, process context */
-static int enic_open(struct net_device *netdev)
+static int enic_admin_chan_reopen(struct enic *enic);
+
+static void enic_schedule_datapath_reset(struct enic *enic)
+{
+ if (READ_ONCE(enic->netdev->reg_state) == NETREG_REGISTERED)
+ schedule_work(&enic->reset);
+}
+
+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,
+ bool schedule_reset_on_failure)
{
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 = {
@@ -1743,6 +1760,37 @@ static int enic_open(struct net_device *netdev)
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) &&
+ (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);
+ if (READ_ONCE(enic->admin_chan_state) !=
+ ENIC_ADMIN_CHAN_DOWN) {
+ err = enic_admin_channel_close(enic);
+ if (READ_ONCE(enic->admin_chan_state) !=
+ ENIC_ADMIN_CHAN_DOWN) {
+ if (schedule_reset_on_failure &&
+ !enic_admin_channel_is_quarantined(enic))
+ enic_schedule_datapath_reset(enic);
+ return err ?: -EBUSY;
+ }
+ }
+ err = enic_admin_chan_reopen(enic);
+ if (err)
+ return err;
+ }
+
err = enic_request_intr(enic);
if (err) {
netdev_err(netdev, "Unable to request irq.\n");
@@ -1801,17 +1849,47 @@ 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)) {
+ /* Commit the replay only if no mailbox fault arrived while station
+ * and receive policy were being programmed. Keep the state lock
+ * through the carrier transition so a later fault necessarily wins
+ * and turns carrier back off.
+ */
+ 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 +1899,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 +1911,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);
@@ -1840,13 +1934,23 @@ static int enic_open(struct net_device *netdev)
return err;
}
+static int enic_open(struct net_device *netdev)
+{
+ return __enic_open(netdev, true);
+}
+
/* 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 +1975,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 +2008,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,6 +2154,46 @@ 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;
+
+ /* Historical async PFs allow HANG_RESET for a V2 VF but reject the
+ * CMD_CAPABILITY query used by the generic helper. Issue the known V2
+ * protocol command directly so that rejection cannot select SOFT_RESET,
+ * which those PFs do not allow.
+ */
+ if (!enic_is_sriov_vf_v2(enic))
+ return vnic_dev_hang_reset(vdev, arg);
+
+ spin_lock_bh(&enic->devcmd_lock);
+ err = vnic_dev_cmd(vdev, CMD_HANG_RESET, &a0, &a1, 1000);
+ 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;
+
+ if (!enic_is_sriov_vf_v2(enic))
+ return vnic_dev_hang_reset_done(vdev, done);
+
+ *done = 0;
+ spin_lock_bh(&enic->devcmd_lock);
+ err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS, &a0, &a1, 1000);
+ if (!err)
+ *done = a0 == 0;
+ spin_unlock_bh(&enic->devcmd_lock);
+
+ return err;
+}
+
static int enic_dev_soft_reset(struct enic *enic)
{
int err;
@@ -2049,12 +2207,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 +2225,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;
@@ -2215,12 +2393,13 @@ static bool enic_control_dma_unresolved(struct enic *enic)
* 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.
*/
-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 +2417,63 @@ 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);
+ /* Capability negotiation and registration establish a new protocol
+ * generation. RX remains quarantined until enic_open() replays the
+ * station and receive policy.
+ */
+ 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 +2482,335 @@ 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, u32 *generation)
+{
+ bool claimed = false;
+
+ /* Both 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);
+ if (!enic->vf_mbox_recovery_active) {
+ enic->vf_mbox_recovery_active = true;
+ *generation = enic->vf_mbox_fault_generation;
+ claimed = true;
+ }
+ spin_unlock_bh(&enic->mbox_state_lock);
+
+ return claimed;
+}
+
+static bool enic_vf_mbox_recovery_finish(struct enic *enic, u32 generation,
+ bool succeeded)
+{
+ bool restart;
+
+ spin_lock_bh(&enic->mbox_state_lock);
+ /* Only a fully committed recovery may consume one late-fault retry. A
+ * failed handshake remains quarantined for an external recovery event;
+ * it must not create an unbounded reset/re-registration loop.
+ */
+ restart = succeeded &&
+ enic->vf_mbox_fault_generation != generation;
+ 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;
+ u32 recovery_generation = 0;
+ 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,
+ &recovery_generation);
+ 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 needs PF registration before enic_open() can install its
+ * station address. A V2 PF reopens afterwards and replays carrier.
+ */
+ 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, false);
+ 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,
+ recovery_generation,
+ !err &&
+ !enic_control_dma_unresolved(enic));
rtnl_unlock();
+ if (restart)
+ schedule_work(&enic->tx_hang_reset);
}
static void enic_tx_hang_reset(struct work_struct *work)
{
struct enic *enic = container_of(work, struct enic, tx_hang_reset);
+ bool mailbox_recovery = false;
+ bool recovery_owned = false;
+ bool restart = false;
+ bool needs_init;
+ bool reopen;
+ u32 recovery_generation = 0;
+ 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;
-
- /* Stop any activity from infiniband */
+ if (reopen && enic_is_sriov_vf_v2(enic)) {
+ recovery_owned =
+ enic_vf_mbox_recovery_begin(enic,
+ &recovery_generation);
+ if (!recovery_owned)
+ goto unlock;
+ mailbox_recovery =
+ READ_ONCE(enic->vf_mbox_reconnect_required) ||
+ READ_ONCE(enic->mbox_tx_poisoned);
+ }
+
+ /* 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;
+ }
- /* 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.
+ if (reopen)
+ err = __enic_open(enic->netdev, false);
+ 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 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,
+ recovery_generation,
+ !err &&
+ !enic_control_dma_unresolved(enic));
rtnl_unlock();
+ if (restart)
+ schedule_work(&enic->tx_hang_reset);
}
static int enic_set_intr_mode(struct enic *enic)
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
index d1b6f13c8002..85fed8beb347 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->tx_hang_reset);
+}
+
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] 12+ messages in thread* Re: [PATCH net-next v3 3/6] enic: recover V2 VF mailbox after request failure
2026-11-18 23:32 ` [PATCH net-next v3 3/6] enic: recover V2 VF mailbox after request failure Satish Kharat
@ 2026-11-23 0:32 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 0:32 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, netdev,
linux-kernel, sebaddel, aradhana, rfaucett
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 3 · 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).
- [High] enic_reset() still sends CMD_SOFT_RESET to V2 VFs through the
generic enic_dev_soft_reset().
- [Medium] The commit message says the patch will "Keep other ENIC
functions' capability and fallback behavior, with INIT deferred until…
- [Medium] The patch adds devcmd_lock around runtime CMD_INIT
(enic_vnic_dev_init()) and the V2 CMD_HANG_RESET/CMD_HANG_RESET_STATUS…
- [Medium] enic: stale generation in enic_vf_mbox_recovery_finish()
causes spurious reset
- [Low] Besides V2 VF mailbox recovery, the commit carries several
changes that stand on their own and affect every ENIC function, with…
--
enic: recover V2 VF mailbox after request failure
This commit adds recovery for V2 VF mailbox failures. After a lost or
inconsistent reply, or a send timeout, the VF reconnects and re-registers
with the PF from the reset workers, using the hang-reset command pair. It
also tracks datapath open/stop pairing, detaches the netdev when a recovery
step fails, quarantines VF RX until registration completes, and moves VF
ACK transmission to a workqueue.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index dde9098357d16..e6232927af808 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);
> }
[Severity: Low]
This isn't a bug, but this locking change looks like a fix for an
existing problem. Before this patch, enic_reset() and enic_pp.c called
enic_reset_addr_lists(), and so __dev_uc_unsync() and __dev_mc_unsync(),
while holding only RTNL.
Could this go in its own patch with a Fixes: tag?
Several other changes in this commit also affect every ENIC function, not
only V2 VFs:
- enic_set_ringparam() gains netif_device_present() checks
- __enic_stop() now frees IRQs before the queue disables and
enic_dev_notify_unset()
- enic_rq_indicate_buf() now tests vf_rx_quarantined for every packet
in the shared RX path
- VF ACKs for PF link state notifications now go through a workqueue
Could these be split out of the 750 line recovery commit, so they can be
reviewed and backported separately?
[ ... ]
> @@ -2036,6 +2154,46 @@ 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;
> +
> + /* Historical async PFs allow HANG_RESET for a V2 VF but reject the
> + * CMD_CAPABILITY query used by the generic helper. Issue the known V2
> + * protocol command directly so that rejection cannot select SOFT_RESET,
> + * which those PFs do not allow.
> + */
> + if (!enic_is_sriov_vf_v2(enic))
> + return vnic_dev_hang_reset(vdev, arg);
> +
> + spin_lock_bh(&enic->devcmd_lock);
> + err = vnic_dev_cmd(vdev, CMD_HANG_RESET, &a0, &a1, 1000);
> + spin_unlock_bh(&enic->devcmd_lock);
> +
> + return err;
> +}
[ ... ]
> @@ -2062,6 +2225,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;
> +}
[Severity: Medium]
The comment here says runtime devcmds share the command registers with
statistics. The V2 branches of enic_dev_hang_reset_start() and
enic_dev_hang_reset_done() take devcmd_lock for the same reason.
Are the other reset commands in these sequences still sent without that
lock?
enic_dev_soft_reset() is unchanged and polls with no lock held:
static int enic_dev_soft_reset(struct enic *enic)
{
...
err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
vnic_dev_soft_reset_done, 0);
...
}
The non-V2 branches also call vnic_dev_hang_reset() and
vnic_dev_hang_reset_done() without the lock. That covers their
CMD_CAPABILITY probes, CMD_HANG_RESET, and the new CMD_SOFT_RESET
fallback.
enic_dev_wait() can poll for up to about 2 seconds. In that window, a
stats read (for example /proc/net/dev) can issue CMD_STATS_DUMP on the
same registers:
enic_get_stats()->enic_dev_stats_dump()
That path holds devcmd_lock but not RTNL. _vnic_dev_cmd() returns -EBUSY
when it sees STAT_BUSY, and vnic_dev_cmd() memsets the shared
vdev->args[].
Before this patch a spurious reset failure was ignored. Now enic_reset()
and enic_tx_hang_reset() call enic_detach_after_recovery_failure() on any
reset error, and nothing in the driver calls netif_device_attach().
Can a concurrent stats read during recovery now leave the netdev detached
for good?
[ ... ]
> @@ -2271,135 +2482,335 @@ static void enic_admin_chan_reopen(struct enic *enic)
[ ... ]
> static void enic_reset(struct work_struct *work)
> {
> struct enic *enic = container_of(work, struct enic, reset);
[ ... ]
> + 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;
> + }
[Severity: High]
Can this permanently detach a V2 VF?
The commit message says deployed async PFs "deny soft reset and its
capability query". The comment in enic_dev_hang_reset_start() also says
SOFT_RESET is something "those PFs do not allow".
Yet enic_reset() still calls the generic enic_dev_soft_reset() for V2
VFs, and that function has no V2 branch.
A queue error on a V2 VF still schedules this worker:
enic_isr_msix_err()
if (enic_log_q_error(enic))
/* schedule recovery from WQ/RQ error */
schedule_work(&enic->reset);
enic_isr_legacy() does the same. This patch also adds a V2-VF-only
trigger: __enic_open() calls enic_schedule_datapath_reset().
When SOFT_RESET is rejected, the worker has already closed the admin
channel and stopped the datapath. It then calls
enic_detach_after_recovery_failure() and skips both
enic_admin_chan_reopen() and __enic_open(). Before this patch the error
was ignored and the device was reopened.
Nothing in the driver calls netif_device_attach(). dev_open(), both reset
workers and enic_set_ringparam() all refuse a non-present device.
Because err is set, enic_vf_mbox_recovery_finish() does not schedule
tx_hang_reset either. So the hang-reset pair added for V2 VFs is never
tried on this path.
Would the interface stay out of service until the driver is rebound?
The last patch in the series still leaves this enic_dev_soft_reset() call
in enic_reset() unchanged.
Should V2 VFs use the hang-reset pair here instead?
> + /* 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;
> + }
> + }
[Severity: Medium]
The commit message says:
"Keep other ENIC functions' capability and fallback behavior, with INIT
deferred until soft reset completes."
Does this match what changes for PFs, legacy VFs and dynamic vNICs?
First, enic_reset() now sends CMD_INIT after SOFT_RESET for every
non-dynamic vNIC. The old enic_reset() never did. The new comment reads
like a fix for an existing PF problem, but there is no Fixes: tag or
separate explanation for it.
Second, the vnic_dev_hang_reset() fallback used to call INIT for every
device:
- err = vnic_dev_soft_reset(vdev, arg);
- if (err)
- return err;
- return vnic_dev_init(vdev, 0);
enic_tx_hang_reset() now reissues INIT only when needs_init &&
!enic_is_dynamic(enic). So dynamic vNICs no longer get INIT on this path.
That matches probe, but it is a behavior change rather than a deferral.
Third, both reset workers now call enic_detach_after_recovery_failure()
when SOFT_RESET, HANG_RESET or INIT fails on any ENIC function, PFs
included. Before, the error was logged and the device was reopened.
Since nothing reattaches the device, one transient firmware failure
during recovery would leave a PF netdev unusable until rebind. The commit
message mentions detaching only for queue-stop failures.
Could the commit message describe these changes for non-V2 functions, or
could they go in separate patches?
[ ... ]
> @@ -2271,135 +2482,335 @@ 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, u32 *generation)
> +{
> + bool claimed = false;
> +
> + /* Both 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);
> + if (!enic->vf_mbox_recovery_active) {
> + enic->vf_mbox_recovery_active = true;
> + *generation = enic->vf_mbox_fault_generation;
> + claimed = true;
> + }
> + spin_unlock_bh(&enic->mbox_state_lock);
> +
> + return claimed;
> +}
> +
> +static bool enic_vf_mbox_recovery_finish(struct enic *enic, u32 generation,
> + bool succeeded)
> +{
> + bool restart;
> +
> + spin_lock_bh(&enic->mbox_state_lock);
> + /* Only a fully committed recovery may consume one late-fault retry. A
> + * failed handshake remains quarantined for an external recovery event;
> + * it must not create an unbounded reset/re-registration loop.
> + */
> + restart = succeeded &&
> + enic->vf_mbox_fault_generation != generation;
> + 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;
> + u32 recovery_generation = 0;
> + 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,
> + &recovery_generation);
> + 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 needs PF registration before enic_open() can install its
> + * station address. A V2 PF reopens afterwards and replays carrier.
> + */
> + 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, false);
> + 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,
> + recovery_generation,
> + !err &&
> + !enic_control_dma_unresolved(enic));
> rtnl_unlock();
> + if (restart)
> + schedule_work(&enic->tx_hang_reset);
> }
>
> static void enic_tx_hang_reset(struct work_struct *work)
> {
> struct enic *enic = container_of(work, struct enic, tx_hang_reset);
> + bool mailbox_recovery = false;
> + bool recovery_owned = false;
> + bool restart = false;
> + bool needs_init;
> + bool reopen;
> + u32 recovery_generation = 0;
> + 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;
> -
> - /* Stop any activity from infiniband */
> + if (reopen && enic_is_sriov_vf_v2(enic)) {
> + recovery_owned =
> + enic_vf_mbox_recovery_begin(enic,
> + &recovery_generation);
> + if (!recovery_owned)
> + goto unlock;
> + mailbox_recovery =
> + READ_ONCE(enic->vf_mbox_reconnect_required) ||
> + READ_ONCE(enic->mbox_tx_poisoned);
> + }
> +
> + /* 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;
> + }
>
> - /* 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.
> + if (reopen)
> + err = __enic_open(enic->netdev, false);
> + 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 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,
> + recovery_generation,
> + !err &&
> + !enic_control_dma_unresolved(enic));
> rtnl_unlock();
> + if (restart)
> + schedule_work(&enic->tx_hang_reset);
> }
>
> static int enic_set_intr_mode(struct enic *enic)
[Severity: Medium]
Can this restart a recovery that has already succeeded?
enic_tx_hang_reset() samples recovery_generation in
enic_vf_mbox_recovery_begin() before enic_admin_channel_close() has
masked the admin interrupt and cancelled admin_msg_work and the other
admin workers. Those run without RTNL. A fault reported from the old
channel in that window still increments vf_mbox_fault_generation.
Examples are a truncated or bad FCS admin completion, a full admin msg
backlog, or a malformed reply.
enic_admin_chan_reopen() then takes its own snapshot after the close and
the hang reset. It registers again and clears
vf_mbox_reconnect_required, because nothing changed relative to that
later snapshot. The late fault is therefore already covered by the
fresh registration.
The same thing happens when __enic_open() sees the flag set again and
runs its own close and enic_admin_chan_reopen() at the top.
enic_vf_mbox_recovery_finish() still compares against the older value
from enic_vf_mbox_recovery_begin(). It sees a mismatch and returns true,
so tx_hang_reset is queued again. enic_reset() has the same tail.
On that second run, vf_mbox_reconnect_required and mbox_tx_poisoned are
both false. So mailbox_recovery is false and the worker calls
enic_dev_hang_notify().
The commit message says HANG_NOTIFY is skipped for mailbox recovery
because it reports an actual Tx hang. Here a hang is reported to
firmware anyway. The worker then closes the admin channel, stops the
datapath and resets a VF that had just recovered.
Should the restart decision use the generation that
enic_admin_chan_reopen() actually committed? Or should it restart only
while vf_mbox_reconnect_required or mbox_tx_poisoned is still set?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-b4-enic-sriov-v2-vf-receive-control-v3-0-2cb25677aa8c%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next v3 4/6] enic: validate V2 VF configuration replies
2026-11-18 23:32 [PATCH net-next v3 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
` (2 preceding siblings ...)
2026-11-18 23:32 ` [PATCH net-next v3 3/6] enic: recover V2 VF mailbox after request failure Satish Kharat
@ 2026-11-18 23:32 ` Satish Kharat
2026-11-23 0:32 ` netdev-bot+sashiko
2026-11-18 23:32 ` [PATCH net-next v3 5/6] enic: manage V2 VF station and administrative MAC Satish Kharat
2026-11-18 23:32 ` [PATCH net-next v3 6/6] enic: configure V2 VF receive mode over mailbox Satish Kharat
5 siblings, 1 reply; 12+ messages in thread
From: Satish Kharat @ 2026-11-18 23:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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.
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.
This patch adds only the VF side of these operations. Administrative-MAC
notification handling is added by the next patch. 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.
Assisted-by: LLM
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
drivers/net/ethernet/cisco/enic/enic.h | 9 +
drivers/net/ethernet/cisco/enic/enic_mbox.c | 490 +++++++++++++++++++++++++++-
drivers/net/ethernet/cisco/enic/enic_mbox.h | 82 +++++
3 files changed, 563 insertions(+), 18 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 22a0ff71a43c..28b24189d5bf 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -245,6 +245,8 @@ enum enic_admin_chan_state {
};
/* Per-instance private data structure */
+struct enic_mac_addr;
+
struct enic {
struct net_device *netdev;
struct pci_dev *pdev;
@@ -373,6 +375,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 85fed8beb347..2326e00a4fea 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,12 +1104,15 @@ 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,
@@ -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] 12+ messages in thread* Re: [PATCH net-next v3 4/6] enic: validate V2 VF configuration replies
2026-11-18 23:32 ` [PATCH net-next v3 4/6] enic: validate V2 VF configuration replies Satish Kharat
@ 2026-11-23 0:32 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 0:32 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, netdev,
linux-kernel, sebaddel, aradhana, rfaucett
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 patch changes how existing, non-configuration mailbox
messages are handled, but the commit message only describes validating…
- [Low] enic_mbox_vf_handle_set_pkt_filter_reply() forces a reconnect for
any errno-style ret_major, meaning one with bits outside…
- [Low] In drivers/net/ethernet/cisco/enic/enic.h the patch puts the
forward declaration `struct enic_mac_addr;` between the existing…
--
enic: validate V2 VF configuration replies
This commit adds the VF-side V2 mailbox operations for adding and deleting
MAC filters and for setting packet filters. It also adds the
administrative-MAC protocol definitions. Reply framing, per-entry MAC
results and applied filter flags are validated. A new VF registration is
forced when a reply is malformed or the PF reports that the VF is no
longer registered.
> diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
> index 22a0ff71a43c6..28b24189d5bfc 100644
> --- a/drivers/net/ethernet/cisco/enic/enic.h
> +++ b/drivers/net/ethernet/cisco/enic/enic.h
> @@ -245,6 +245,8 @@ enum enic_admin_chan_state {
> };
>
> /* Per-instance private data structure */
> +struct enic_mac_addr;
> +
> struct enic {
> struct net_device *netdev;
> struct pci_dev *pdev;
[Severity: Low]
This isn't a bug, but the forward declaration now sits between the
"Per-instance private data structure" comment and struct enic. The comment
now appears to describe struct enic_mac_addr.
Could the declaration go above the comment instead?
[ ... ]
> diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
> index 85fed8beb347e..2326e00a4fea6 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_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;
> + }
[Severity: Low]
Why does an errno-style ret_major force a reconnect only for
SET_PKT_FILTER replies?
The comment in enic_mbox_vf_classify_reply() says:
/* Some deployed peers return a negative errno in this 16-bit field.
That function treats such a value as a plain -EIO with recovery left at
ENIC_MBOX_VF_REPLY_OK. This applies to ADD_DEL_MAC replies in
enic_mbox_vf_handle_add_del_mac_reply() and to the capability, register
and unregister replies in enic_mbox_vf_handle_reply().
The commit message says reconnect is reserved for "malformed or
indeterminate replies". An errno-style rejection of SET_PKT_FILTER still
sets mbox_send_disabled and vf_rx_quarantined and schedules tx_hang_reset.
The protocol-defined MSG_NOT_SUPPORTED bit for the same rejection only
returns -EOPNOTSUPP.
Is this asymmetry intended? If so, could the code or the commit message
explain why an errno-style rejection is indeterminate here but not for a
MAC operation?
[ ... ]
> @@ -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);
> +}
[Severity: Low]
Should the commit message mention that this also changes how existing,
non-configuration messages are handled? It only says:
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.
A PF_LINK_STATE_NOTIF with a short payload used to be dropped when
enic_mbox_vf_payload_ok() failed. It is a notification, not a reply, but
it now goes through enic_mbox_vf_malformed_msg() and
enic_mbox_vf_require_reconnect(). That sets mbox_send_disabled and
vf_rx_quarantined and schedules tx_hang_reset.
Short CAPABILITY, REGISTER and UNREGISTER replies used to be dropped too,
and the waiter would time out. The same is true of any PF message whose
msg_len fails the new check in enic_mbox_recv_handler(). These are now
claimed, completed with -EIO, and a reconnect is forced.
enic_mbox_vf_handle_reply() also sends ret_major through
enic_mbox_vf_classify_reply() now. A VF_NOT_REGISTERED bit on any of the
three existing replies clears vf_registered and schedules a reset.
The return values seen by the existing callers change as well:
enic_mbox_vf_capability_check(): -EIO instead of -EOPNOTSUPP for a
GENERIC rejection
enic_mbox_vf_register() / enic_mbox_vf_unregister(): -EIO,
-EOPNOTSUPP or -ENODEV instead of -ENODEV or -EACCES
Could these behaviour changes be described in the commit message?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-b4-enic-sriov-v2-vf-receive-control-v3-0-2cb25677aa8c%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next v3 5/6] enic: manage V2 VF station and administrative MAC
2026-11-18 23:32 [PATCH net-next v3 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
` (3 preceding siblings ...)
2026-11-18 23:32 ` [PATCH net-next v3 4/6] enic: validate V2 VF configuration replies Satish Kharat
@ 2026-11-18 23:32 ` Satish Kharat
2026-11-23 0:32 ` netdev-bot+sashiko
2026-11-18 23:32 ` [PATCH net-next v3 6/6] enic: configure V2 VF receive mode over mailbox Satish Kharat
5 siblings, 1 reply; 12+ messages in thread
From: Satish Kharat @ 2026-11-18 23:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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.
Install the station address during open and remove it during an ordinary
stop. Detach the netdev under RTNL before remove-time channel teardown so
receive-mode work cannot race the mailbox shutdown. 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.
Assisted-by: LLM
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 | 594 ++++++++++++++++++++++++++-
drivers/net/ethernet/cisco/enic/enic_mbox.c | 30 ++
6 files changed, 648 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 28b24189d5bf..5a830a7f8d92 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -357,6 +357,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;
@@ -373,6 +376,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;
@@ -506,6 +519,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 e6232927af80..46a5f46b192e 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,469 @@ 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)
+{
+ 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 (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 (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];
+ u8 selected[ETH_ALEN];
+ 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);
+ 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);
+ eth_hw_addr_set(enic->netdev, selected);
+ if (!zero_policy || changed)
+ 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];
+ u8 random_addr[ETH_ALEN];
+ u8 selected[ETH_ALEN];
+ u8 policy[ETH_ALEN];
+ 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);
+ eth_hw_addr_set(enic->netdev, selected);
+ if (!zero_policy || changed)
+ enic->netdev->addr_assign_type = zero_policy ?
+ NET_ADDR_RANDOM : 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_set_mac_address_dynamic(struct net_device *netdev, void *p)
{
struct enic *enic = netdev_priv(netdev);
@@ -1071,6 +1537,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);
+ 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)
@@ -1737,6 +2250,7 @@ static int __enic_open(struct net_device *netdev,
bool schedule_reset_on_failure)
{
struct enic *enic = netdev_priv(netdev);
+ bool vf_mac_added = false;
bool clear_cqs = false;
unsigned int i;
int stop_err = 0;
@@ -1834,6 +2348,25 @@ 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;
+ }
+
+ err = enic_vf_station_addr_replace(enic, netdev->dev_addr);
+ 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);
@@ -1897,6 +2430,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++) {
@@ -1940,7 +2482,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;
@@ -1974,6 +2516,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) &&
+ 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);
@@ -2019,7 +2570,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)
@@ -2454,9 +3005,21 @@ static int enic_admin_chan_reopen(struct enic *enic)
return close_err ?: err;
}
enic_reset_addr_lists(enic);
+ 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;
+ }
/* Capability negotiation and registration establish a new protocol
- * generation. RX remains quarantined until enic_open() replays the
- * station and receive policy.
+ * generation after authoritative MAC policy is refreshed. RX remains
+ * quarantined until enic_open() replays station and receive policy.
*/
spin_lock_bh(&enic->mbox_state_lock);
if (enic->vf_mbox_fault_generation != recovery_generation ||
@@ -2475,6 +3038,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
@@ -2573,7 +3137,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);
@@ -2722,7 +3286,7 @@ static void enic_tx_hang_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);
if (stop_err || enic_control_dma_unresolved(enic)) {
@@ -3656,6 +4220,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
@@ -3687,6 +4254,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);
@@ -3812,6 +4385,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;
@@ -3883,9 +4458,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);
@@ -3904,6 +4482,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 2326e00a4fea..2b8f0841e8ca 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] 12+ messages in thread* Re: [PATCH net-next v3 5/6] enic: manage V2 VF station and administrative MAC
2026-11-18 23:32 ` [PATCH net-next v3 5/6] enic: manage V2 VF station and administrative MAC Satish Kharat
@ 2026-11-23 0:32 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 0:32 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, netdev,
linux-kernel, sebaddel, aradhana, rfaucett
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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] During probe, enic_vf_admin_mac_refresh() runs before
register_netdev() and now sets netdev->addr_assign_type.
- [Medium] enic: untracked PF station MACs while closed in
enic_vf_admin_mac_work()
- [Medium] enic: stale dev_addr used in __enic_open() when admin MAC work
is pending
- [Low] The commit message says the patch will 'Detach the netdev under
RTNL before remove-time channel teardown so receive-mode work cannot…
--
enic: manage V2 VF station and administrative MAC
This patch makes the V2 VF manage its station address through the V2
mailbox MAC operation. A replacement is sent as one DEL+ADD request, and
a partial result makes the VF register again. The PF administrative MAC
is treated as authoritative: notifications are handled from a delayed
worker, and the policy is re-read with CMD_GET_MAC_ADDR after every
registration.
> Install the station address during open and remove it during an ordinary
> stop. Detach the netdev under RTNL before remove-time channel teardown so
> receive-mode work cannot race the mailbox shutdown.
[Severity: Low]
Does this sentence describe a change made by this patch? In the baseline,
enic_remove() already detaches the netdev under RTNL before the admin
channel teardown:
rtnl_lock();
netif_device_detach(netdev);
rtnl_unlock();
The enic_remove() hunks here only add enic_vf_admin_mac_quiesce(),
enic_vf_admin_mac_purge() and a longer comment.
Could the commit message be reworded so it doesn't attribute the
detach-before-teardown ordering to this patch?
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index e6232927af808..46a5f46b192eb 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
[ ... ]
> @@ -1064,6 +1067,469 @@ static int enic_set_mac_addr(struct net_device *netdev, char *addr)
[ ... ]
> +/* 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)
> +{
[ ... ]
> + changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> + eth_hw_addr_set(enic->netdev, selected);
> + if (!zero_policy || changed)
> + enic->netdev->addr_assign_type = zero_policy ?
> + NET_ADDR_RANDOM : NET_ADDR_SET;
[Severity: Medium]
Is this assignment safe on the probe path? enic_probe() now calls
enic_vf_admin_mac_refresh() before register_netdev(). With a nonzero
PF-administered MAC, !zero_policy is true, so addr_assign_type becomes
NET_ADDR_SET. With a zero policy and a newly picked random address, it
becomes NET_ADDR_RANDOM.
register_netdevice() only fills perm_addr for NET_ADDR_PERM:
net/core/dev.c:register_netdevice() {
...
if (dev->addr_assign_type == NET_ADDR_PERM)
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
...
}
So the sequence on every V2 VF probe with a PF-assigned MAC is:
enic_probe()
enic_mbox_vf_register()
enic_vf_admin_mac_refresh()
addr_assign_type = NET_ADDR_SET
enic_set_mac_addr()
register_netdev()
register_netdevice()
perm_addr copy skipped
Doesn't this register the VF with an all-zero perm_addr? ethtool -P would
show 00:00:00:00:00:00, and sysfs would report addr_assign_type 3, as if
userspace had changed the address.
Before this patch, enic never touched addr_assign_type, so the VF
registered as NET_ADDR_PERM and perm_addr was filled in. Later patches in
the series don't appear to change this.
Should the probe-time refresh leave addr_assign_type as NET_ADDR_PERM, so
register_netdevice() still records the permanent address?
[ ... ]
> @@ -1064,6 +1067,469 @@ 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)
> +{
> + 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 (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 (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];
> + u8 selected[ETH_ALEN];
> + 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()) {
[Severity: Medium]
Can a pending admin MAC change make this open fail?
enic_vf_admin_mac_notify() runs from admin_msg_work without RTNL and
updates vf_admin_mac immediately. netdev->dev_addr, however, is only
updated by enic_vf_admin_mac_work(). That worker backs off on
rtnl_trylock() and retries every 10ms while RTNL is held.
Suppose the notification lands while dev_open(), enic_reset() or
enic_tx_hang_reset() holds RTNL. __enic_open() then reaches this call
with the old dev_addr. Nothing here looks at vf_admin_mac_pending or
vf_admin_mac, so the request asks the PF to install an address which
is no longer the administrative MAC.
The PF presumably rejects that ADD with all preceding DELETEs skipped.
In that case enic_vf_station_addr_replace() returns -EACCES without
requesting a reconnect.
For an ordinary open this is a spurious failure of the link-up
request. In the reset paths the result looks worse:
enic_reset()
rtnl_lock()
enic_admin_chan_reopen()
enic_vf_admin_mac_refresh()
enic_vf_admin_mac_rearm()
<- notification arrives, worker backs off on RTNL
__enic_open(netdev, false)
enic_vf_station_addr_replace(enic, old dev_addr) -> -EACCES
enic_admin_channel_close()
enic_vf_admin_mac_quiesce()
cancel_delayed_work_sync(&enic->vf_admin_mac_work)
WRITE_ONCE(enic->vf_registered, false)
enic_tx_hang_reset() follows the same sequence. Recovery ends with the
admin channel closed and the datapath down, and the pending
administrative MAC is never applied.
Should __enic_open() apply a pending vf_admin_mac under RTNL before
installing the station, as the worker would have done? Or should a
policy rejection here be deferred until the worker has run, rather
than failing the open and tearing down the channel?
> + 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);
> + 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);
> + eth_hw_addr_set(enic->netdev, selected);
> + if (!zero_policy || changed)
> + 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];
> + u8 random_addr[ETH_ALEN];
> + u8 selected[ETH_ALEN];
> + u8 policy[ETH_ALEN];
> + 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);
> + eth_hw_addr_set(enic->netdev, selected);
> + if (!zero_policy || changed)
> + enic->netdev->addr_assign_type = zero_policy ?
> + NET_ADDR_RANDOM : 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_set_mac_address_dynamic(struct net_device *netdev, void *p)
> {
> struct enic *enic = netdev_priv(netdev);
[Severity: Medium]
When the datapath is closed, this branch treats a nonzero notification
as a station address the PF has already installed. Can that lose track
of a PF-installed station when more than one notification arrives
while the interface is down?
Consider nonzero policies P1 then P2, both with datapath_open false:
enic_vf_admin_mac_work() [P1]
vf_station_addr_valid is false, so station_installed = true
enic_vf_station_addr_set(enic, P1)
enic_vf_admin_mac_work() [P2]
vf_station_addr_valid is true and vf_station_addr != P2,
so station_installed = false
dev_addr = P2, vf_station_addr is still P1
Nothing in the closed branch deletes P1, and P2 is never recorded in
vf_station_addr. If a third notification (P3, a zero policy, or P1
again) arrives before the next open, dev_addr moves on. P2 is then no
longer referenced anywhere in struct enic.
The following __enic_open() calls enic_vf_station_addr_replace().
That only deletes the tracked vf_station_addr (P1) and the new
dev_addr, so P2 stays installed at the PF as a unicast station filter.
It remains there until the next unregister or registration.
struct enic only tracks a single vf_station_addr. Should the closed
branch first delete a differing tracked station, as the datapath_open
branch does with enic_vf_station_addr_del(), so the newly installed
address can be recorded? Or is there a reason the mailbox cannot be
used here while the datapath is down?
A related question for enic_vf_admin_mac_refresh(): when it consumes
a pending nonzero notification, it clears vf_admin_mac_pending and
sets dev_addr, but never calls enic_vf_station_addr_set(). Is the next
open's equal-address DEL+ADD enough to cover that case?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-b4-enic-sriov-v2-vf-receive-control-v3-0-2cb25677aa8c%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next v3 6/6] enic: configure V2 VF receive mode over mailbox
2026-11-18 23:32 [PATCH net-next v3 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
` (4 preceding siblings ...)
2026-11-18 23:32 ` [PATCH net-next v3 5/6] enic: manage V2 VF station and administrative MAC Satish Kharat
@ 2026-11-18 23:32 ` Satish Kharat
2026-11-23 0:32 ` netdev-bot+sashiko
5 siblings, 1 reply; 12+ messages in thread
From: Satish Kharat @ 2026-11-18 23:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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. Treat
PF denial as degraded coverage consistently during open and runtime
updates.
Track detailed per-address results so idempotent outcomes converge and
stable policy denials do not consume the retry budget. Require fresh
registration when an ambiguous whole-request error can leave a DELETE
partially applied, while keeping local pre-submit and add-only failures on
the normal retry path. Keep the station address out of both secondary
address lists.
Select the asynchronous netdev operations only for V2 VFs. Replay receive
mode after successful reset, hang-reset, and direct MTU reopen paths so the
current snapshot converges after every internal datapath rebuild.
Assisted-by: LLM
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
drivers/net/ethernet/cisco/enic/enic.h | 3 +
drivers/net/ethernet/cisco/enic/enic_main.c | 476 +++++++++++++++++++++++++++-
2 files changed, 468 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 5a830a7f8d92..294e09d44da8 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -395,6 +395,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 46a5f46b192e..47b84bc282f7 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)
@@ -1621,17 +1623,404 @@ 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 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_station_addr_valid &&
+ ether_addr_equal(ha->addr, enic->vf_station_addr)))
+ 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_station_addr_valid &&
+ ether_addr_equal(ha->addr, enic->vf_station_addr))
+ 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)
+{
+ struct enic_vf_mac_op *ops;
+ struct enic_mac_addr *macs;
+ unsigned int projected_mc = enic->mc_count;
+ unsigned int projected_uc = enic->uc_count;
+ bool has_delete = false;
+ bool permanent_add = false;
+ bool reconnect = false;
+ bool retryable_add = 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;
+
+ /* The protocol carries all changed unicast and multicast addresses in
+ * one request. Besides matching the native ABI, this bounds time spent
+ * in the RTNL-held asynchronous receive-mode callback to one MAC reply.
+ */
+ err = enic_mbox_vf_add_del_macs(enic, macs, num_ops);
+ if (err) {
+ /* The PF may have applied any prefix before a request-wide failure.
+ * A batch containing DELETE can therefore leave stale acceptance.
+ * Fresh registration is the cleanup boundary unless transport DMA is
+ * already poisoned and awaiting its reset fence.
+ */
+ 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 (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 broad_enable_needed;
+ bool broad_withdrawal;
+ bool filter_needed;
+ bool target_filter_updated = false;
+ u16 applied_broad;
+ u16 prefilter_flags;
+ u16 applied_flags;
+ int err;
+
+ 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);
@@ -2252,6 +2641,10 @@ static int __enic_open(struct net_device *netdev,
struct enic *enic = netdev_priv(netdev);
bool vf_mac_added = false;
bool clear_cqs = false;
+ u16 vf_filter_applied;
+ u16 vf_filter_flags;
+ unsigned int vf_mc_count;
+ unsigned int vf_uc_count;
unsigned int i;
int stop_err = 0;
int err, ret;
@@ -2347,7 +2740,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");
@@ -2365,9 +2757,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);
@@ -2575,6 +2989,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;
@@ -2591,6 +3006,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;
@@ -3198,6 +3615,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
@@ -3343,6 +3766,8 @@ static void enic_tx_hang_reset(struct work_struct *work)
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
@@ -3612,6 +4037,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,
@@ -4295,7 +4744,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;
@@ -4458,9 +4909,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] 12+ messages in thread* Re: [PATCH net-next v3 6/6] enic: configure V2 VF receive mode over mailbox
2026-11-18 23:32 ` [PATCH net-next v3 6/6] enic: configure V2 VF receive mode over mailbox Satish Kharat
@ 2026-11-23 0:32 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 0:32 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, netdev,
linux-kernel, sebaddel, aradhana, rfaucett
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] Exact-filter ADDs that the PF denied permanently
(PERMANENT_MASK) leave ha->sync_cnt at 0.
- [Medium] enic_vf_sync_mac_filters() handles any SKIPPED DELETE as fail-
closed: it calls enic_mbox_vf_require_reconnect(), which sets…
- [Medium] When an ADD-only ADD_DEL_MAC request fails as a whole with
-EIO (for example ret_major = GENERIC or an errno-like value, which…
- [Low] The comment above the enic_mbox_vf_add_del_macs() call in
enic_vf_sync_mac_filters() says the single batch "bounds time spent in…
- [Low] In enic_vf_sync_mac_filters(), the per-result loop sets `err =
-EIO` when a DELETE result would decrement an installed-filter counter…
--
enic: configure V2 VF receive mode over mailbox
This patch adds an ndo_set_rx_mode_async callback for V2 VFs. The
callback sends unicast/multicast address changes and packet-filter
settings to the PF over the mailbox. It orders broad-mode transitions
around one exact-filter batch and maps per-address PF results to retry,
reconnect or stable-denial outcomes. Receive mode is also replayed after
reset, hang-reset and MTU reopen.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 46a5f46b192eb..47b84bc282f7d 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
[ ... ]
> @@ -1621,17 +1623,404 @@ static int enic_set_mac_address(struct net_device *netdev, void *p)
[ ... ]
> +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_station_addr_valid &&
> + ether_addr_equal(ha->addr, enic->vf_station_addr))
> + continue;
> + if (add) {
> + if (ha->sync_cnt || *projected_count >= max_filters)
> + continue;
[Severity: Medium]
Do addresses that the PF has already denied permanently keep using up the
exact-filter budget here?
When enic_vf_sync_mac_filters() sees ENIC_MAC_ADDR_FLAG_PERMANENT_MASK on
an ADD, it sets permanent_add and continues, so ha->sync_cnt stays 0. On
the next run, this loop collects the same denied entries again in list
order. Each one increments *projected_count toward the 31 UC / 32 MC
limit.
Take 35 secondary UC addresses where the PF rejects the first 5 with
NOT_PERMITTED. Only 26 get installed. Each later run fills projected_uc
from 26 to 31 with the same 5 denied entries. The last 4 addresses are
never sent, even though the PF has 5 free slots.
If the PF also denies promiscuous mode, those 4 addresses get no coverage
at all. Does this match "leaving overflow entries unsynchronized for later
convergence" in the commit message?
[ ... ]
> + /* The protocol carries all changed unicast and multicast addresses in
> + * one request. Besides matching the native ABI, this bounds time spent
> + * in the RTNL-held asynchronous receive-mode callback to one MAC reply.
> + */
[Severity: Low]
Is this comment accurate? One call to enic_set_vf_rx_mode() can make up
to three serialized, blocking mailbox transactions, all under RTNL. enic
sets neither request_ops_lock nor queue_mgmt_ops, so
netdev_lock_ops_compat() takes rtnl_lock():
enic_set_vf_rx_mode()
enic_vf_set_pkt_filter(prefilter_flags) /* broad pre-enable */
enic_vf_set_pkt_filter(flags) /* broad withdrawal */
enic_vf_sync_mac_filters()
enic_mbox_vf_add_del_macs()
A combined transition, such as applied PROMISC to requested ALLMULTI,
sets both broad_enable_needed and broad_withdrawal. The second
SET_PKT_FILTER cannot hit the cache, because vf_pkt_filter_requested was
just set to prefilter_flags.
Each request first polls the send for up to ENIC_MBOX_POLL_TIMEOUT_US,
then waits up to 3000 ms in enic_mbox_wait_reply(). A PF that always
replies just under the timeout could keep RTNL held for roughly 9 seconds
per call. The core may also retry up to 4 times on -EAGAIN or -EIO.
> + err = enic_mbox_vf_add_del_macs(enic, macs, num_ops);
> + if (err) {
> + /* The PF may have applied any prefix before a request-wide failure.
> + * A batch containing DELETE can therefore leave stale acceptance.
> + * Fresh registration is the cleanup boundary unless transport DMA is
> + * already poisoned and awaiting its reset fence.
> + */
> + 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;
> + }
[Severity: Medium]
What happens when an ADD-only batch fails as a whole with -EIO?
enic_mbox_vf_classify_reply() maps a non-zero ret_major to -EIO with
recovery allowed. As the comment above says, the PF "may have applied any
prefix before a request-wide failure". With has_delete false, no reconnect
is requested. sync_cnt and uc_count/mc_count are also not updated for any
addresses the PF did install.
Suppose such an address is removed before a retry succeeds, or after the
retry budget runs out. The core frees it in __hw_addr_list_reconcile()
while its sync_cnt is still 0. enic_vf_collect_mac_ops() only emits a
DELETE when sync_cnt is non-zero:
if (!ha->sync_cnt || ha->refcount != ha->sync_cnt)
continue;
So no DELETE is ever sent. Could the PF keep accepting traffic for that
address, and keep one of its 32 UC slots in use, until the next fresh
registration? The local projection would then also overestimate free
capacity.
> +
> + 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;
> + }
[Severity: Medium]
Is a full reconnect the right response to a SKIPPED DELETE?
A skipped entry means the PF did not apply it, so sync_cnt for that
address is still accurate. But enic_mbox_vf_require_reconnect() sets
mbox_send_disabled and vf_rx_quarantined, and it schedules tx_hang_reset.
The existing comment in enic_vf_station_addr_replace() notes that the PF
can report preceding DELETEs as skipped when it rejects an ADD by policy:
/* A policy-rejected ADD can be reported with all preceding DELETEs
* skipped. No operation changed state in that coherent result tuple.
*/
This batch always puts deletes before adds. A permanently denied ADD
keeps sync_cnt at 0, so it is resent in every later batch. If the PF uses
the same semantics here, could every address-list change that removes a
synced secondary MAC trigger another VF datapath reset while the denied
address is still in the list?
There is a related problem when the PF also skips the other ADDs in that
batch. retryable_add takes precedence over permanent_add, so -EAGAIN is
returned. Each retry rebuilds the same batch and gets the same result
until NETIF_RX_MODE_RETRY_MAX. Could one denied address then stop all the
other addresses from ever being installed?
> + 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 (retryable_add) {
> + err = -EAGAIN;
> + } else if (permanent_add) {
> + err = -EACCES;
> + }
[Severity: Low]
Can the -EIO set in the WARN_ON_ONCE() branch above be lost here? This
chain overwrites err without checking its earlier value.
If the same batch also contains a permanently denied ADD, err becomes
-EACCES, and enic_set_vf_rx_mode() turns that into 0. The detected counter
inconsistency is then reported as a successful update. With a skipped ADD,
it is downgraded to -EAGAIN instead.
This is a defensive path that should not normally be reachable, but
should the earlier -EIO take precedence?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-b4-enic-sriov-v2-vf-receive-control-v3-0-2cb25677aa8c%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread