* [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX
@ 2026-11-30 13:58 Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 1/6] net: add netif_rx_mode_schedule_update() Satish Kharat
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Satish Kharat @ 2026-11-30 13:58 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Willem de Bruijn
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
An ENIC V2 VF relies on the PF to program its station address and receive
filters. Add VF mailbox support for the station address, secondary address
lists and packet-filter modes. Serialize VF requests around the single
expected reply slot. Unsolicited PF notifications retain their own path.
Patch 1 adds a netdev helper for starting a new bounded receive-mode retry
sequence. Patch 2 serializes VF request/reply ownership. Patches 3 and 4
recover after uncertain mailbox state and validate configuration replies.
Patches 5 and 6 handle station/admin MAC policy and receive-mode replay.
Net-next includes both prerequisite fixes.
- b3ae89a2e167 ("enic: retain admin-channel DMA until queues stop")
- 65230b3ffd75 ("enic: require DEVCMD2 and set the V2 VF mailbox source")
The six patches prepare the VF side. The in-tree V2 PF enable path remains
dormant until a later series supplies the PF mailbox and cleanup contracts
and registers sriov_configure. The VF expects a compatible PF. Queue-error
recovery still uses VF SOFT_RESET with that PF's command permission. VF
soft-reset failure detaches the device. The direct ERR_EBADSTATE handling
mentioned in the v3 reply belongs to a separate PF setup/teardown path.
Ordinary VF stop requests deletion of the tracked station address while
the VF is registered. Firmware readback covered the tested administrative
MAC changes while the VF was closed and on the subsequent open.
A coherent request-wide MAC error relies on the PF rejecting the request
before it applies operations. Per-entry failures use detailed replies;
lost or indeterminate replies require reconnect. A rejected station ADD
can cause a PF to skip earlier station DELETEs at precheck. The secondary
filter batch has no station flag, and an unexpected skipped secondary
DELETE still requires reconnect. The earlier uniform spoof-check denial
test does not establish fairness for arbitrary per-entry policy denials.
Hardware validation
- With a compatible PF, the final VF reopened after down/up and adopted a
changed PF-assigned MAC while preserving its probe-time perm_addr.
Firmware readback confirmed secondary unicast and multicast filters were
added and removed while the station entry stayed installed. Bidirectional
ICMP completed without packet loss.
- Earlier hardware A/B tests recovered one valid exact-filter entry at
each tested unicast and multicast capacity boundary by excluding the
all-zero address. Switching between fixed and delegated MAC policy
preserved perm_addr and reported SET and RANDOM, respectively.
- Earlier full-stack PF/VF tests covered VFIO passthrough, VF recreation,
module reload, ring resizing, and bidirectional ICMP, TCP and UDP,
including jumbo traffic. In separate tests, three pairings using the
historical async driver passed traffic and lost lockdep coverage after
warnings from that driver.
- Earlier instrumented hardware tests showed that a queued mailbox
recovery skipped HANG_NOTIFY and reset once a normal reopen had
cleared the fault. After an injected failure following CMD_ENABLE,
the unwind cleared pending RX completions. The VF reopened on the same
rings and traffic resumed. An injected QP_DISABLE error still allowed
VF reopen and traffic once both admin queues had stopped.
LLM assisted with implementation, review, draft wording and
test tooling. Sashiko findings were used in v4 review and triage.
Changes in v4
- Name the first callers of netif_rx_mode_schedule_update().
- Extend devcmd_lock coverage to generic hang-reset and soft-reset
start and status commands. Explain the compatible-PF requirement
for V2 VF soft reset.
- Carry the mailbox recovery reason in a dedicated work item. Only genuine
Tx watchdog work sends HANG_NOTIFY. After successful recovery, queue
another pass only if reconnect or poisoned-send state is still pending.
- Clarify the handling of malformed existing replies and notifications and
the conservative reconnect for an errno-style packet-filter failure.
- Apply pending PF policy before station installation and, after a clean
policy rejection, refresh and retry once if the selected address changes.
Record probe-time perm_addr while preserving RANDOM/SET assignment.
- Exclude zero and wrong-list-class addresses from requested counts and
exact-filter operations. The PF keeps one entry per MAC. Keep counter
inconsistency errors sticky when processing later ADD results.
- Link to v3: https://patch.msgid.link/20261118-b4-enic-sriov-v2-vf-receive-control-v3-0-2cb25677aa8c@cisco.com
Changes in v3
- Depend on the two admin/source fixes from net v7. Keep generic datapath
DMA quarantine outside this series.
- Preserve admin DMA until queue stop is confirmed, keep VF registration
and datapath lifecycle balanced, and authenticate PF completions from CQ
metadata. Bound recovery after failed handshakes.
- Reserve 31 secondary UC slots because the PF counts the station in the
same 32-entry table. Replay receive mode after a datapath rebuild.
- Link to v2: https://patch.msgid.link/20260929-b4-enic-sriov-v2-vf-receive-control-v2-0-5962c10061b2@cisco.com
Changes in v2
- Bound reconnect, respect a cached administrative MAC while closed and
reconcile receive mode in one asynchronous callback.
- Link to v1: https://patch.msgid.link/20260921-b4-enic-sriov-v2-vf-receive-control-v1-0-67a0a6e08d43@cisco.com
Link: https://lore.kernel.org/netdev/20261109-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v7-0-30ca6f467673@cisco.com/
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
Satish Kharat (6):
net: add netif_rx_mode_schedule_update()
enic: serialize V2 VF mailbox requests
enic: recover V2 VF mailbox after request failure
enic: validate V2 VF configuration replies
enic: manage V2 VF station and administrative MAC
enic: configure V2 VF receive mode over mailbox
drivers/net/ethernet/cisco/enic/enic.h | 58 +
drivers/net/ethernet/cisco/enic/enic_admin.c | 39 +-
drivers/net/ethernet/cisco/enic/enic_dev.c | 11 +
drivers/net/ethernet/cisco/enic/enic_dev.h | 1 +
drivers/net/ethernet/cisco/enic/enic_ethtool.c | 5 +
drivers/net/ethernet/cisco/enic/enic_main.c | 1729 ++++++++++++++++++++++--
drivers/net/ethernet/cisco/enic/enic_mbox.c | 751 +++++++++-
drivers/net/ethernet/cisco/enic/enic_mbox.h | 84 ++
drivers/net/ethernet/cisco/enic/enic_rq.c | 11 +-
drivers/net/ethernet/cisco/enic/vnic_dev.c | 21 +-
drivers/net/ethernet/cisco/enic/vnic_dev.h | 2 +
include/linux/netdevice.h | 1 +
net/core/dev_addr_lists.c | 21 +
13 files changed, 2597 insertions(+), 137 deletions(-)
---
base-commit: d6816d9a93b66a12bf01e10037e377f3333ad6cc
change-id: 20260916-b4-enic-sriov-v2-vf-receive-control-b5c40bdae5b9
Best regards,
--
Satish Kharat <satishkh@cisco.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next v4 1/6] net: add netif_rx_mode_schedule_update()
2026-11-30 13:58 [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
@ 2026-11-30 13:58 ` Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 2/6] enic: serialize V2 VF mailbox requests Satish Kharat
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Satish Kharat @ 2026-11-30 13:58 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Willem de Bruijn
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
Add a receive-mode scheduling helper for callers which start a new update
after a state transition. Cancel a pending retry and reset its backoff
before queueing the immediate update so the preceding operation's retry
state cannot shorten the new operation's bounded retry sequence.
The helper preserves address-list synchronization state. Callers which
need to replay configuration lost by the device must unsynchronize the
affected address lists before scheduling the update.
The first callers are added by the enic V2 VF patches later in this
series: the administrative-MAC notification, the V2 VF set-MAC path, and
the _enic_change_mtu(), soft-reset and hang-reset reopen paths.
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
include/linux/netdevice.h | 1 +
net/core/dev_addr_lists.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 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
* [PATCH net-next v4 2/6] enic: serialize V2 VF mailbox requests
2026-11-30 13:58 [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 1/6] net: add netif_rx_mode_schedule_update() Satish Kharat
@ 2026-11-30 13:58 ` Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 3/6] enic: recover V2 VF mailbox after request failure Satish Kharat
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Satish Kharat @ 2026-11-30 13:58 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Willem de Bruijn
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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 registration
in the unregister path after taking the mutex. 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 bypass the VF request mutex.
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 v4 3/6] enic: recover V2 VF mailbox after request failure
2026-11-30 13:58 [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 1/6] net: add netif_rx_mode_schedule_update() Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 2/6] enic: serialize V2 VF mailbox requests Satish Kharat
@ 2026-11-30 13:58 ` Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 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-30 13:58 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Willem de Bruijn
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
A mailbox send can complete and still lose its reply. The VF then cannot
know whether the PF changed its state. A send-completion timeout is
different because the admin-WQ descriptor may still belong to the device.
Reconnect after a lost or inconsistent reply. For a posted-send timeout,
retain the mapping on the admin WQ, block sends, and start recovery after
releasing the sender lock. The prerequisite admin fix releases that graph
only when both admin queues stop; a retained graph cannot be reset or
reopened, and a final remove-time recheck may reclaim it.
Run V2 VF mailbox recovery on its own work item while sharing the
hang-reset sequence with the Tx watchdog. Claim queued mailbox recovery
only while reconnect or poisoned-send state remains pending. Ordinary open
may already have consumed the fault while holding RTNL. Keep genuine
watchdog work separate so coalesced mailbox and Tx events cannot lose
their scheduling reasons.
The VF recovery path requires the hang-reset pair, so issue CMD_HANG_RESET
directly rather than through the generic capability probe. Keep generic
capability selection for other ENIC functions. Serialize each reset start
command and status poll under devcmd_lock. Issue runtime INIT after soft
reset completes for non-dynamic functions. Dynamic vNICs follow their
probe-time initialization contract. A reset or INIT failure detaches the
netdev until the driver is rebound. Skip HANG_NOTIFY for mailbox recovery
because it reports an actual Tx hang. Queue-error recovery can still
use CMD_SOFT_RESET on a V2 VF. That path requires a PF which permits the
command and its status/INIT sequence, and it detaches the VF if soft reset
fails.
Close admin and stop the datapath before reset. Check stop, reset, INIT,
registration and reopen results before proceeding. Close an admin channel
opened for a VF when its datapath reopen fails. After successful recovery,
queue a follow-up only while reconnect or poisoned-send state remains
pending. Fresh registration consumes faults from the prior channel; a
failed handshake remains quarantined.
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 completed software opens with datapath_open. IFF_UP can remain
set after failed internal recovery, so a later close must not disable
NAPI twice. Later VF station-address handling also uses this flag to
identify an open datapath. 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.
In an earlier instrumented hardware run, a two-second test hold after
CMD_ENABLE let 4,080 RX completions accumulate before an injected
mailbox-state failure. The late unwind cleared them. A guarded reopen
using the same rings found none and traffic resumed. The test required
all data queues to report stopped.
Keep VF carrier off and receive delivery quarantined until the final
open-time mailbox check succeeds. Later patches install the station
address and initial packet filter before CMD_ENABLE and schedule
secondary address-list replay after open.
Defer ACK transmission off RX dispatch, authenticate PF completions from
CQ metadata, serialize runtime INIT, and update address-list counters
under their synchronization lock.
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
drivers/net/ethernet/cisco/enic/enic.h | 28 ++
drivers/net/ethernet/cisco/enic/enic_admin.c | 37 +-
drivers/net/ethernet/cisco/enic/enic_ethtool.c | 5 +
drivers/net/ethernet/cisco/enic/enic_main.c | 611 +++++++++++++++++++++----
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, 794 insertions(+), 107 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 15f17019c076..ae7367cd1a60 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -254,6 +254,7 @@ struct enic {
struct timer_list notify_timer;
struct work_struct reset;
struct work_struct tx_hang_reset;
+ struct work_struct vf_mbox_recovery_work;
struct work_struct change_mtu_work;
struct msix_entry *msix_entry;
struct enic_msix_entry *msix;
@@ -314,6 +315,29 @@ struct enic {
enum enic_admin_chan_state admin_chan_state;
/* Blocks sends throughout close, partial open and timeout recovery. */
bool mbox_send_disabled;
+ /* A send timeout leaves WQ descriptor ownership unresolved until channel
+ * shutdown proves that both admin queues stopped.
+ */
+ bool mbox_tx_poisoned;
+ /* After a lost or inconsistent reply, the VF cannot know whether the PF
+ * applied the request. Reconnect during the next open or reset.
+ */
+ bool vf_mbox_reconnect_required;
+ /* Prevent a mailbox fault from scheduling another worker during
+ * recovery. A failed recovery remains quarantined until a later
+ * external recovery event or close/open.
+ */
+ bool vf_mbox_recovery_active;
+ /* Detect a new fault during VF re-registration before clearing the
+ * reconnect-required state.
+ */
+ u32 vf_mbox_fault_generation;
+ /* One slow-path-owned predicate keeps the RX hot path fail-closed while
+ * VF registration is lost or receive state may not match the PF.
+ */
+ bool vf_rx_quarantined;
+ /* RTNL protects software open/stop pairing; this does not prove DMA stop. */
+ bool datapath_open;
struct vnic_wq admin_wq;
struct vnic_rq admin_rq;
struct vnic_cq admin_cq[2];
@@ -346,6 +370,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..9c4b94a94980 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,12 +2154,81 @@ static int enic_dev_open(struct enic *enic)
return err;
}
+static int enic_dev_hang_reset_start(struct vnic_dev *vdev, int arg)
+{
+ struct enic *enic = vnic_dev_priv(vdev);
+ u64 a0 = (u32)arg, a1 = 0;
+ int err;
+
+ /* A V2 VF recovers with the hang-reset pair; issue CMD_HANG_RESET
+ * directly to skip the generic helper's CMD_CAPABILITY round-trip on
+ * the VF command path.
+ */
+ spin_lock_bh(&enic->devcmd_lock);
+ if (enic_is_sriov_vf_v2(enic))
+ err = vnic_dev_cmd(vdev, CMD_HANG_RESET, &a0, &a1, 1000);
+ else
+ err = vnic_dev_hang_reset(vdev, arg);
+ spin_unlock_bh(&enic->devcmd_lock);
+
+ return err;
+}
+
+static int enic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
+{
+ struct enic *enic = vnic_dev_priv(vdev);
+ u64 a0 = 0, a1 = 0;
+ int err;
+
+ *done = 0;
+ spin_lock_bh(&enic->devcmd_lock);
+ if (enic_is_sriov_vf_v2(enic)) {
+ err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS, &a0, &a1, 1000);
+ if (!err)
+ *done = a0 == 0;
+ } else {
+ err = vnic_dev_hang_reset_done(vdev, done);
+ }
+ spin_unlock_bh(&enic->devcmd_lock);
+
+ return err;
+}
+
+/* The soft-reset poll shares the device-command registers with statistics and
+ * other netdev operations; serialize each step under devcmd_lock, matching the
+ * hang-reset and runtime-init paths. Otherwise a concurrent CMD_STATS_DUMP can
+ * collide on the shared registers and make a reset spuriously report failure.
+ */
+static int enic_dev_soft_reset_start(struct vnic_dev *vdev, int arg)
+{
+ struct enic *enic = vnic_dev_priv(vdev);
+ int err;
+
+ spin_lock_bh(&enic->devcmd_lock);
+ err = vnic_dev_soft_reset(vdev, arg);
+ spin_unlock_bh(&enic->devcmd_lock);
+
+ return err;
+}
+
+static int enic_dev_soft_reset_done(struct vnic_dev *vdev, int *done)
+{
+ struct enic *enic = vnic_dev_priv(vdev);
+ int err;
+
+ spin_lock_bh(&enic->devcmd_lock);
+ err = vnic_dev_soft_reset_done(vdev, done);
+ spin_unlock_bh(&enic->devcmd_lock);
+
+ return err;
+}
+
static int enic_dev_soft_reset(struct enic *enic)
{
int err;
- err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
- vnic_dev_soft_reset_done, 0);
+ err = enic_dev_wait(enic->vdev, enic_dev_soft_reset_start,
+ enic_dev_soft_reset_done, 0);
if (err)
netdev_err(enic->netdev, "vNIC soft reset failed, err %d\n",
err);
@@ -2049,12 +2236,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 +2254,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 +2422,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 +2446,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 +2511,342 @@ static void enic_admin_chan_reopen(struct enic *enic)
*/
schedule_work(&enic->link_notify_work);
}
+
+ return 0;
+}
+
+static bool enic_vf_mbox_recovery_begin(struct enic *enic,
+ bool mailbox_recovery)
+{
+ bool claimed = false;
+
+ /* Reset workers claim ownership only after taking RTNL. This state
+ * lock still makes the handoff atomic with mailbox fault producers.
+ */
+ spin_lock_bh(&enic->mbox_state_lock);
+ /* Open may have consumed a queued mailbox fault while holding RTNL. */
+ if (!enic->vf_mbox_recovery_active &&
+ (!mailbox_recovery ||
+ READ_ONCE(enic->vf_mbox_reconnect_required) ||
+ READ_ONCE(enic->mbox_tx_poisoned))) {
+ enic->vf_mbox_recovery_active = true;
+ claimed = true;
+ }
+ spin_unlock_bh(&enic->mbox_state_lock);
+
+ return claimed;
+}
+
+static bool enic_vf_mbox_recovery_finish(struct enic *enic, bool succeeded)
+{
+ bool restart;
+
+ spin_lock_bh(&enic->mbox_state_lock);
+ /* Restart only for a fault still outstanding after recovery. Fresh
+ * registration may already have consumed a fault from the old channel.
+ * A failed handshake remains quarantined for an external recovery event.
+ */
+ restart = succeeded &&
+ (READ_ONCE(enic->vf_mbox_reconnect_required) ||
+ READ_ONCE(enic->mbox_tx_poisoned));
+ enic->vf_mbox_recovery_active = false;
+ spin_unlock_bh(&enic->mbox_state_lock);
+
+ return restart;
}
static void enic_reset(struct work_struct *work)
{
struct enic *enic = container_of(work, struct enic, reset);
+ bool recovery_owned = false;
+ bool restart = false;
+ bool reopen;
+ int stop_err = 0;
+ int err = 0;
if (!netif_running(enic->netdev))
return;
-
rtnl_lock();
-
- if (!netif_running(enic->netdev))
+ reopen = netif_running(enic->netdev);
+ if (!reopen || !netif_device_present(enic->netdev))
goto unlock;
- /* Stop any activity from infiniband */
+ /* Serialize a live V2 VF protocol recovery and preserve its one bounded
+ * late-fault follow-up.
+ */
+ if (reopen && enic_is_sriov_vf_v2(enic)) {
+ recovery_owned = enic_vf_mbox_recovery_begin(enic, false);
+ if (!recovery_owned)
+ goto unlock;
+ }
+
+ /* Stop any activity from infiniband. */
enic_set_api_busy(enic, true);
- /* Close the V2 admin/MBOX channel before the soft reset. Release its
- * DMA resources only after both queues report stopped; otherwise
- * quarantine the channel and abandon the reset.
+ /* Close the admin channel before reset without sending DEL_MAC; reset and
+ * fresh registration discard the old VF-requested state. Release its DMA
+ * resources only after both queues report stopped. Otherwise quarantine
+ * the channel and abandon the reset.
*/
if (enic_has_admin_chan(enic)) {
- enic_admin_channel_close(enic);
+ int close_err = enic_admin_channel_close(enic);
+
+ if (close_err && enic_admin_channel_is_quarantined(enic))
+ netdev_err(enic->netdev,
+ "Admin queue did not stop: %d\n", close_err);
+ else if (close_err)
+ netdev_warn(enic->netdev,
+ "Admin QP disable returned: %d\n",
+ close_err);
/* Channel close has drained registration replies. */
if (enic_is_sriov_vf_v2(enic))
WRITE_ONCE(enic->vf_registered, false);
}
- if (enic_admin_channel_is_quarantined(enic)) {
- /* Core close excludes netpoll and clears __LINK_STATE_START first. */
- dev_close(enic->netdev);
- goto reset_out;
- }
+ if (READ_ONCE(enic->datapath_open))
+ stop_err = __enic_stop(enic->netdev);
- enic_stop(enic->netdev);
if (enic_is_sriov_vf_v2(enic))
enic_mbox_vf_link_state_reset(enic);
+ if (stop_err || enic_control_dma_unresolved(enic)) {
+ err = stop_err ?: -EBUSY;
+ netdev_err(enic->netdev,
+ "Recovery blocked after close (datapath stop %d)\n",
+ stop_err);
+ goto reset_out;
+ }
+
+ err = enic_dev_soft_reset(enic);
+ if (err) {
+ enic_detach_after_recovery_failure(enic);
+ goto reset_out;
+ }
+ /* Firmware completes SOFT_RESET in OPEN state. Non-dynamic vNICs need
+ * CMD_INIT to recreate and enable their LIF before resource restore.
+ */
+ if (!enic_is_dynamic(enic)) {
+ err = enic_vnic_dev_init(enic);
+ if (err) {
+ netdev_err(enic->netdev,
+ "vNIC init after soft reset failed: %d\n",
+ err);
+ enic_detach_after_recovery_failure(enic);
+ goto reset_out;
+ }
+ }
- enic_dev_soft_reset(enic);
enic_reset_addr_lists(enic);
enic_init_vnic_resources(enic);
enic_set_rss_nic_cfg(enic);
enic_dev_set_ig_vlan_rewrite_mode(enic);
enic_ext_cq(enic);
- if (enic_open(enic->netdev))
+ /* A V2 VF 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,
+ !err &&
+ !enic_control_dma_unresolved(enic));
rtnl_unlock();
+ if (restart)
+ schedule_work(&enic->vf_mbox_recovery_work);
}
-static void enic_tx_hang_reset(struct work_struct *work)
+static void enic_hang_reset(struct enic *enic, bool mailbox_recovery)
{
- struct enic *enic = container_of(work, struct enic, tx_hang_reset);
+ bool recovery_owned = false;
+ bool restart = false;
+ bool needs_init;
+ bool reopen;
+ int stop_err = 0;
+ int err = 0;
rtnl_lock();
-
- if (!netif_running(enic->netdev))
+ reopen = netif_running(enic->netdev);
+ if (!reopen || !netif_device_present(enic->netdev))
goto unlock;
+ if (reopen && enic_is_sriov_vf_v2(enic)) {
+ recovery_owned = enic_vf_mbox_recovery_begin(enic,
+ mailbox_recovery);
+ if (!recovery_owned)
+ goto unlock;
+ }
- /* Stop any activity from infiniband */
+ /* Stop any activity from infiniband. */
enic_set_api_busy(enic, true);
- /* Close the V2 admin/MBOX channel before the hang reset. Release its
- * DMA resources only after both queues report stopped; otherwise
- * quarantine the channel and abandon the reset.
+ /* Report an actual Tx hang before stopping and cleaning its queue. Mailbox
+ * recovery reuses the VF-allowed hang-reset pair but must not report a
+ * spurious Tx hang. As in the soft-reset path, skip DEL_MAC because reset
+ * and fresh registration are the cleanup boundary. Release admin DMA only
+ * after both queues report stopped; otherwise quarantine the channel and
+ * abandon the reset.
*/
+ if (!mailbox_recovery)
+ enic_dev_hang_notify(enic);
if (enic_has_admin_chan(enic)) {
- enic_admin_channel_close(enic);
+ int close_err = enic_admin_channel_close(enic);
+
+ if (close_err && enic_admin_channel_is_quarantined(enic))
+ netdev_err(enic->netdev,
+ "Admin queue did not stop: %d\n", close_err);
+ else if (close_err)
+ netdev_warn(enic->netdev,
+ "Admin QP disable returned: %d\n",
+ close_err);
/* Channel close has drained registration replies. */
if (enic_is_sriov_vf_v2(enic))
WRITE_ONCE(enic->vf_registered, false);
}
- if (enic_admin_channel_is_quarantined(enic)) {
- dev_close(enic->netdev);
- goto reset_out;
- }
-
- enic_dev_hang_notify(enic);
- enic_stop(enic->netdev);
+ if (READ_ONCE(enic->datapath_open))
+ stop_err = __enic_stop(enic->netdev);
if (enic_is_sriov_vf_v2(enic))
enic_mbox_vf_link_state_reset(enic);
+ if (stop_err || enic_control_dma_unresolved(enic)) {
+ err = stop_err ?: -EBUSY;
+ netdev_err(enic->netdev,
+ "Recovery blocked after close (datapath stop %d)\n",
+ stop_err);
+ goto hang_reset_out;
+ }
- enic_dev_hang_reset(enic);
+ err = enic_dev_hang_reset(enic, &needs_init);
+ if (err) {
+ enic_detach_after_recovery_failure(enic);
+ goto hang_reset_out;
+ }
+ /* Native HANG_RESET preserves firmware's desired admin state and the
+ * firmware reinitializes it. Only the legacy SOFT_RESET fallback sets
+ * needs_init and requires the deferred CMD_INIT below.
+ */
+ if (needs_init && !enic_is_dynamic(enic)) {
+ err = enic_vnic_dev_init(enic);
+ if (err) {
+ netdev_err(enic->netdev,
+ "vNIC init after hang reset failed: %d\n",
+ err);
+ enic_detach_after_recovery_failure(enic);
+ goto hang_reset_out;
+ }
+ }
enic_reset_addr_lists(enic);
enic_init_vnic_resources(enic);
enic_set_rss_nic_cfg(enic);
enic_dev_set_ig_vlan_rewrite_mode(enic);
enic_ext_cq(enic);
- if (enic_open(enic->netdev))
- goto reset_out;
+ if (enic_is_sriov_vf_v2(enic)) {
+ err = enic_admin_chan_reopen(enic);
+ if (err)
+ goto hang_reset_out;
+ }
+
+ if (reopen)
+ err = __enic_open(enic->netdev, false);
+ if (reopen && err) {
+ if (enic_is_sriov_vf_v2(enic) && enic_has_admin_chan(enic)) {
+ int close_err = enic_admin_channel_close(enic);
- /* Re-establish the admin/MBOX channel after the data path is back up.
- * It was fully torn down by enic_admin_channel_close() above;
- * enic_admin_chan_reopen() reopens it and, for a PF re-pushes link
- * state, or for a VF re-runs the probe-time PF handshake.
+ WRITE_ONCE(enic->vf_registered, false);
+ if (close_err)
+ netdev_warn(enic->netdev,
+ "Admin close after datapath reopen failure returned: %d\n",
+ close_err);
+ }
+ netdev_err(enic->netdev,
+ "Failed to reopen datapath after hang reset: %d\n", err);
+ goto hang_reset_out;
+ }
+
+ /* A PF reopens its admin channel after the datapath and re-pushes link
+ * state. The VF handshake, which open depends on, completed above.
*/
- if (enic_has_admin_chan(enic))
- enic_admin_chan_reopen(enic);
- if (enic_is_sriov_vf_v2(enic) &&
- enic_admin_channel_is_quarantined(enic))
- dev_close(enic->netdev);
+ if (enic_has_admin_chan(enic) && !enic_is_sriov_vf_v2(enic)) {
+ int admin_err = enic_admin_chan_reopen(enic);
-reset_out:
+ if (admin_err)
+ netdev_err(enic->netdev,
+ "Failed to reopen PF admin channel after hang reset: %d\n",
+ admin_err);
+ if (!err)
+ err = admin_err;
+ }
+
+hang_reset_out:
/* Allow infiniband to fiddle with the device again */
enic_set_api_busy(enic, false);
- call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+ if (reopen)
+ call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
unlock:
+ if (recovery_owned)
+ restart = enic_vf_mbox_recovery_finish(enic,
+ !err &&
+ !enic_control_dma_unresolved(enic));
rtnl_unlock();
+ if (restart)
+ schedule_work(&enic->vf_mbox_recovery_work);
+}
+
+static void enic_tx_hang_reset(struct work_struct *work)
+{
+ struct enic *enic = container_of(work, struct enic, tx_hang_reset);
+
+ enic_hang_reset(enic, false);
+}
+
+static void enic_vf_mbox_recovery_work(struct work_struct *work)
+{
+ struct enic *enic = container_of(work, struct enic,
+ vf_mbox_recovery_work);
+
+ enic_hang_reset(enic, true);
}
static int enic_set_intr_mode(struct enic *enic)
@@ -3289,6 +3736,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
enic_rfs_flw_tbl_init(enic);
INIT_WORK(&enic->reset, enic_reset);
INIT_WORK(&enic->tx_hang_reset, enic_tx_hang_reset);
+ INIT_WORK(&enic->vf_mbox_recovery_work, enic_vf_mbox_recovery_work);
INIT_WORK(&enic->change_mtu_work, enic_change_mtu_work);
for (i = 0; i < enic->wq_count; i++)
@@ -3465,6 +3913,7 @@ static void enic_remove(struct pci_dev *pdev)
disable_work_sync(&enic->reset);
disable_work_sync(&enic->tx_hang_reset);
+ disable_work_sync(&enic->vf_mbox_recovery_work);
disable_work_sync(&enic->change_mtu_work);
rtnl_lock();
netif_device_detach(netdev);
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
index d1b6f13c8002..3579d2980a24 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c
@@ -18,6 +18,8 @@
#define ENIC_MBOX_POLL_TIMEOUT_US 5000000
#define ENIC_MBOX_POLL_INTERVAL_US 100
+static void enic_mbox_vf_kick_recovery(struct enic *enic);
+
static void enic_mbox_fill_hdr(struct enic *enic, struct enic_mbox_hdr *hdr,
u8 msg_type,
u16 dst_vnic_id, u16 msg_len, u64 msg_num)
@@ -43,6 +45,7 @@ static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
size_t total_len = sizeof(struct enic_mbox_hdr) + payload_len;
struct vnic_wq *wq = &enic->admin_wq;
struct wq_enet_desc *desc;
+ bool vf_timeout_recovery = false;
bool reply_expected = false;
unsigned long timeout;
dma_addr_t dma_addr;
@@ -157,7 +160,20 @@ static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
* or free the buffer: the device may still DMA from dma_addr.
* Mark the channel unusable so no further sends are attempted.
*/
+ spin_lock_bh(&enic->mbox_state_lock);
WRITE_ONCE(enic->mbox_send_disabled, true);
+ WRITE_ONCE(enic->mbox_tx_poisoned, true);
+ if (enic_is_sriov_vf_v2(enic)) {
+ /* The request may have changed PF receive policy even though
+ * local descriptor ownership is still uncertain. Fail the VF
+ * closed and do not turn this into an ordinary protocol
+ * reconnect; the admin-channel lifecycle owns final reclamation.
+ */
+ WRITE_ONCE(enic->vf_rx_quarantined, true);
+ enic->vf_mbox_fault_generation++;
+ vf_timeout_recovery = true;
+ }
+ spin_unlock_bh(&enic->mbox_state_lock);
}
netdev_dbg(enic->netdev,
@@ -174,6 +190,8 @@ static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
spin_unlock_bh(&enic->mbox_state_lock);
}
mutex_unlock(&enic->mbox_lock);
+ if (vf_timeout_recovery)
+ enic_mbox_vf_kick_recovery(enic);
return err;
}
@@ -192,6 +210,105 @@ static int enic_mbox_send_reply(struct enic *enic, u8 msg_type,
payload_len, msg_num, true, 0);
}
+struct enic_mbox_vf_ack {
+ struct list_head list;
+ u64 msg_num;
+ u16 ret_major;
+ u8 msg_type;
+};
+
+static void enic_mbox_vf_ack_work(struct work_struct *work)
+{
+ struct enic *enic = container_of(work, struct enic, vf_ack_work);
+ struct enic_mbox_vf_ack *pending;
+
+ for (;;) {
+ struct enic_mbox_generic_reply ack = {};
+ u8 msg_type;
+ int err;
+
+ spin_lock_bh(&enic->vf_ack_lock);
+ if (list_empty(&enic->vf_ack_list)) {
+ spin_unlock_bh(&enic->vf_ack_lock);
+ break;
+ }
+ pending = list_first_entry(&enic->vf_ack_list,
+ struct enic_mbox_vf_ack, list);
+ list_del(&pending->list);
+ enic->vf_ack_count--;
+ spin_unlock_bh(&enic->vf_ack_lock);
+
+ if (READ_ONCE(enic->mbox_send_disabled)) {
+ kfree(pending);
+ continue;
+ }
+
+ msg_type = pending->msg_type;
+ ack.ret_major = cpu_to_le16(pending->ret_major);
+ err = enic_mbox_send_reply(enic, msg_type, ENIC_MBOX_DST_PF,
+ &ack, sizeof(ack), pending->msg_num);
+ kfree(pending);
+ if (err && net_ratelimit())
+ netdev_warn(enic->netdev,
+ "MBOX: failed to send ACK type %u: %d\n",
+ msg_type, err);
+ }
+}
+
+static void enic_mbox_vf_queue_ack(struct enic *enic, u8 msg_type,
+ u64 msg_num, u16 ret_major)
+{
+ struct enic_mbox_vf_ack *pending;
+
+ if (READ_ONCE(enic->mbox_send_disabled))
+ return;
+ pending = kmalloc_obj(*pending, GFP_ATOMIC);
+ if (!pending) {
+ if (net_ratelimit())
+ netdev_warn(enic->netdev,
+ "MBOX: dropping ACK type %u: no memory\n",
+ msg_type);
+ return;
+ }
+ pending->msg_num = msg_num;
+ pending->ret_major = ret_major;
+ pending->msg_type = msg_type;
+
+ spin_lock_bh(&enic->vf_ack_lock);
+ if (READ_ONCE(enic->mbox_send_disabled) ||
+ enic->vf_ack_count >= ENIC_ADMIN_DESC_COUNT) {
+ spin_unlock_bh(&enic->vf_ack_lock);
+ kfree(pending);
+ if (net_ratelimit())
+ netdev_warn(enic->netdev,
+ "MBOX: dropping ACK type %u: queue unavailable\n",
+ msg_type);
+ return;
+ }
+ list_add_tail(&pending->list, &enic->vf_ack_list);
+ enic->vf_ack_count++;
+ spin_unlock_bh(&enic->vf_ack_lock);
+ schedule_work(&enic->vf_ack_work);
+}
+
+void enic_mbox_vf_ack_cancel(struct enic *enic)
+{
+ struct enic_mbox_vf_ack *pending, *tmp;
+ LIST_HEAD(discard);
+
+ if (!enic->mbox_initialized)
+ return;
+ cancel_work_sync(&enic->vf_ack_work);
+ spin_lock_bh(&enic->vf_ack_lock);
+ list_splice_init(&enic->vf_ack_list, &discard);
+ enic->vf_ack_count = 0;
+ spin_unlock_bh(&enic->vf_ack_lock);
+ list_for_each_entry_safe(pending, tmp, &discard, list) {
+ list_del(&pending->list);
+ kfree(pending);
+ }
+}
+
static int enic_mbox_vf_send_request(struct enic *enic, u8 request_type,
u8 expected_reply, void *payload,
u16 payload_len)
@@ -201,6 +318,34 @@ static int enic_mbox_vf_send_request(struct enic *enic, u8 request_type,
expected_reply);
}
+static void enic_mbox_vf_mark_reconnect_locked(struct enic *enic,
+ bool registration_lost)
+{
+ lockdep_assert_held(&enic->mbox_state_lock);
+
+ if (registration_lost)
+ WRITE_ONCE(enic->vf_registered, false);
+ enic->vf_mbox_fault_generation++;
+ WRITE_ONCE(enic->vf_mbox_reconnect_required, true);
+ WRITE_ONCE(enic->mbox_send_disabled, true);
+ WRITE_ONCE(enic->vf_rx_quarantined, true);
+}
+
+static void enic_mbox_vf_kick_recovery(struct enic *enic)
+{
+ bool schedule = false;
+
+ enic_mbox_vf_link_state_set_running(enic, false);
+
+ spin_lock_bh(&enic->mbox_state_lock);
+ if (!enic->vf_mbox_recovery_active && netif_running(enic->netdev))
+ schedule = true;
+ spin_unlock_bh(&enic->mbox_state_lock);
+
+ if (schedule)
+ schedule_work(&enic->vf_mbox_recovery_work);
+}
+
static int enic_mbox_wait_reply(struct enic *enic, unsigned long timeout_ms)
{
unsigned long left;
@@ -211,9 +356,9 @@ static int enic_mbox_wait_reply(struct enic *enic, unsigned long timeout_ms)
if (left)
return 0;
- /* Invalidate a request that the handler has not already accepted. A
- * delayed reply cannot match a later request because message numbers are
- * monotonic across channel reopen.
+ /* Invalidate a request that the handler has not already accepted. Whether
+ * losing the reply invalidates the current protocol generation is an
+ * operation-specific decision made by the caller.
*/
spin_lock_bh(&enic->mbox_state_lock);
if (enic->mbox_expected_reply) {
@@ -476,9 +621,8 @@ static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload,
u64 msg_num)
{
struct enic_mbox_pf_link_state_notif_msg *notif = payload;
- struct enic_mbox_pf_link_state_ack_msg ack = {};
u32 link_state = le32_to_cpu(notif->link_state);
- int err;
+ u16 ret_major = 0;
spin_lock_bh(&enic->vf_link_state_lock);
switch (link_state) {
@@ -499,16 +643,16 @@ static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload,
default:
netdev_warn(enic->netdev, "MBOX: unknown link state %u\n",
link_state);
- ack.ack.ret_major = cpu_to_le16(ENIC_MBOX_ERR_GENERIC);
+ ret_major = ENIC_MBOX_ERR_GENERIC;
break;
}
spin_unlock_bh(&enic->vf_link_state_lock);
- err = enic_mbox_send_reply(enic, ENIC_MBOX_PF_LINK_STATE_ACK,
- ENIC_MBOX_DST_PF, &ack, sizeof(ack), msg_num);
- if (err && net_ratelimit())
- netdev_warn(enic->netdev,
- "MBOX: failed to send link state ACK: %d\n", err);
+ /* Notification dispatch must not wait behind a synchronous request send:
+ * its matching reply may be queued behind this notification.
+ */
+ enic_mbox_vf_queue_ack(enic, ENIC_MBOX_PF_LINK_STATE_ACK, msg_num,
+ ret_major);
}
void enic_mbox_vf_link_state_reset(struct enic *enic)
@@ -533,6 +677,17 @@ void enic_mbox_vf_link_state_set_running(struct enic *enic, bool running)
spin_unlock_bh(&enic->vf_link_state_lock);
}
+void enic_mbox_vf_require_reconnect(struct enic *enic)
+{
+ /* A fresh REGISTER transaction lets the PF discard any VF-requested
+ * configuration whose final state became uncertain.
+ */
+ spin_lock_bh(&enic->mbox_state_lock);
+ enic_mbox_vf_mark_reconnect_locked(enic, false);
+ spin_unlock_bh(&enic->mbox_state_lock);
+ enic_mbox_vf_kick_recovery(enic);
+}
+
static bool enic_mbox_vf_payload_ok(struct enic *enic, u8 msg_type,
u16 payload_len, size_t min_len)
{
@@ -608,6 +763,8 @@ static void enic_mbox_recv_handler(struct enic *enic, void *buf,
netdev_warn(enic->netdev,
"MBOX: truncated message (len %u < %zu)\n",
len, sizeof(*hdr));
+ if (!enic->vf_state)
+ enic_mbox_vf_require_reconnect(enic);
return;
}
@@ -764,7 +921,12 @@ void enic_mbox_init(struct enic *enic)
mutex_init(&enic->vf_mbox_request_lock);
init_completion(&enic->mbox_comp);
spin_lock_init(&enic->mbox_state_lock);
+ spin_lock_init(&enic->vf_ack_lock);
+ INIT_LIST_HEAD(&enic->vf_ack_list);
+ INIT_WORK(&enic->vf_ack_work, enic_mbox_vf_ack_work);
enic->mbox_msg_num = 0;
+ if (enic_is_sriov_vf_v2(enic))
+ WRITE_ONCE(enic->vf_rx_quarantined, true);
enic->mbox_initialized = true;
} else {
reinit_completion(&enic->mbox_comp);
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.h b/drivers/net/ethernet/cisco/enic/enic_mbox.h
index 60409bad2f28..37bc41a900f4 100644
--- a/drivers/net/ethernet/cisco/enic/enic_mbox.h
+++ b/drivers/net/ethernet/cisco/enic/enic_mbox.h
@@ -90,6 +90,8 @@ int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
int enic_mbox_send_link_state(struct enic *enic, u16 vf_id, u32 link_state);
void enic_mbox_vf_link_state_reset(struct enic *enic);
void enic_mbox_vf_link_state_set_running(struct enic *enic, bool running);
+void enic_mbox_vf_ack_cancel(struct enic *enic);
+void enic_mbox_vf_require_reconnect(struct enic *enic);
int enic_mbox_vf_capability_check(struct enic *enic);
int enic_mbox_vf_register(struct enic *enic);
int enic_mbox_vf_unregister(struct enic *enic);
diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
index ccbf5c9a21d0..80fe7e819c37 100644
--- a/drivers/net/ethernet/cisco/enic/enic_rq.c
+++ b/drivers/net/ethernet/cisco/enic/enic_rq.c
@@ -330,8 +330,6 @@ static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
u16 bytes_written, vlan_tci, checksum;
u32 rss_hash;
- rqstats->packets++;
-
cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, &ingress_port,
&fcoe, &eop, &sop, &rss_type, &csum_not_calc,
&rss_hash, &bytes_written, &packet_error,
@@ -340,8 +338,15 @@ static void enic_rq_indicate_buf(struct enic *enic, struct vnic_rq *rq,
&tcp_udp_csum_ok, &udp, &tcp, &ipv4_csum_ok, &ipv6,
&ipv4, &ipv4_fragment, &fcs_ok);
- if (enic_rq_pkt_error(rq, packet_error, fcs_ok, bytes_written))
+ if (enic_rq_pkt_error(rq, packet_error, fcs_ok, bytes_written)) {
+ rqstats->packets++;
+ return;
+ }
+ if (unlikely(READ_ONCE(enic->vf_rx_quarantined))) {
+ dev_core_stats_rx_dropped_inc(enic->netdev);
return;
+ }
+ rqstats->packets++;
if (eop && bytes_written > 0) {
/* Good receive
diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.c b/drivers/net/ethernet/cisco/enic/vnic_dev.c
index 92eec1455ceb..a78bd58f950f 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_dev.c
+++ b/drivers/net/ethernet/cisco/enic/vnic_dev.c
@@ -721,17 +721,23 @@ int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg)
{
u64 a0 = (u32)arg, a1 = 0;
int wait = 1000;
- int err;
+ vdev->hang_reset_uses_soft_reset = false;
if (vnic_dev_capable(vdev, CMD_HANG_RESET)) {
return vnic_dev_cmd(vdev, CMD_HANG_RESET,
&a0, &a1, wait);
- } else {
- err = vnic_dev_soft_reset(vdev, arg);
- if (err)
- return err;
- return vnic_dev_init(vdev, 0);
}
+
+ /* enic_dev_wait() polls SOFT_RESET_STATUS. INIT follows reset completion
+ * in the driver, after the ordinary close has succeeded.
+ */
+ vdev->hang_reset_uses_soft_reset = true;
+ return vnic_dev_soft_reset(vdev, arg);
+}
+
+bool vnic_dev_hang_reset_uses_soft_reset(struct vnic_dev *vdev)
+{
+ return vdev->hang_reset_uses_soft_reset;
}
int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
@@ -742,6 +748,9 @@ int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
*done = 0;
+ if (vdev->hang_reset_uses_soft_reset)
+ return vnic_dev_soft_reset_done(vdev, done);
+
if (vnic_dev_capable(vdev, CMD_HANG_RESET_STATUS)) {
err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS,
&a0, &a1, wait);
diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.h b/drivers/net/ethernet/cisco/enic/vnic_dev.h
index 6a4d7ce3b636..ca5a9d4bd39d 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_dev.h
+++ b/drivers/net/ethernet/cisco/enic/vnic_dev.h
@@ -95,6 +95,7 @@ struct vnic_dev {
dma_addr_t stats_pa;
struct vnic_sriov_stats *sriov_stats;
dma_addr_t sriov_stats_pa;
+ bool hang_reset_uses_soft_reset;
struct vnic_devcmd_fw_info *fw_info;
dma_addr_t fw_info_pa;
enum vnic_proxy_type proxy;
@@ -160,6 +161,7 @@ int vnic_dev_intr_coal_timer_info(struct vnic_dev *vdev);
int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg);
int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg);
int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done);
+bool vnic_dev_hang_reset_uses_soft_reset(struct vnic_dev *vdev);
int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done);
void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
enum vnic_dev_intr_mode intr_mode);
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next v4 4/6] enic: validate V2 VF configuration replies
2026-11-30 13:58 [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
` (2 preceding siblings ...)
2026-11-30 13:58 ` [PATCH net-next v4 3/6] enic: recover V2 VF mailbox after request failure Satish Kharat
@ 2026-11-30 13:58 ` Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 5/6] enic: manage V2 VF station and administrative MAC Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 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-30 13:58 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Willem de Bruijn
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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 the caller's MAC
operation array available through reply handling so the VF can check
each echoed operation.
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 entries carrying a result flag
other than SKIPPED. Idempotent DUPLICATE and NOT_FOUND outcomes count.
Successful entries have no result flag.
Treat a short existing capability, register or unregister reply as a
protocol fault when it matches the pending transaction. A malformed PF
link-state notification can also leave state uncertain and requires
reconnect. An errno-style packet-filter error leaves no authoritative
applied mask, so reconnect rather than retaining the previous mask.
Return stable policy errors to callers while retaining retry semantics for
operations that made no state change. A coherent top-level MAC-operation
failure remains an ordinary error. Reserve reconnect for malformed or
indeterminate replies and explicit registration loss.
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.
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 ae7367cd1a60..2c494c8ae23d 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -244,6 +244,8 @@ enum enic_admin_chan_state {
ENIC_ADMIN_CHAN_QUARANTINED,
};
+struct enic_mac_addr;
+
/* Per-instance private data structure */
struct enic {
struct net_device *netdev;
@@ -376,6 +378,13 @@ struct enic {
unsigned int vf_ack_count;
u64 mbox_expected_msg_num;
u8 mbox_expected_reply;
+ int mbox_reply_status;
+ u16 mbox_reply_filter_flags;
+ /* The request mutex keeps this caller-owned reply array alive until the
+ * matching reply handler has copied all per-address result flags.
+ */
+ struct enic_mac_addr *mbox_reply_mac_addrs;
+ u16 mbox_reply_mac_count;
bool mbox_initialized;
/* PF: per-VF MBOX state, allocated when SRIOV V2 is enabled */
diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
index 3579d2980a24..5afb45033772 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
* [PATCH net-next v4 5/6] enic: manage V2 VF station and administrative MAC
2026-11-30 13:58 [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
` (3 preceding siblings ...)
2026-11-30 13:58 ` [PATCH net-next v4 4/6] enic: validate V2 VF configuration replies Satish Kharat
@ 2026-11-30 13:58 ` Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 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-30 13:58 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Willem de Bruijn
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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/ADD pair
for the target. Prepend a DELETE for a different tracked station when
present. If the PF reports a partial replacement, require the VF to
register again before accepting traffic.
Treat the PF administrative MAC as authoritative. Process notifications
outside receive dispatch and preserve a VF-selected address when policy
delegates that choice. Refresh policy with CMD_GET_MAC_ADDR after a
successful registration and protect VF worker shutdown and restart
against teardown and recovery. Schedule a receive-mode update after
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.
Initialize perm_addr from the selected probe address while retaining its
assignment type, including NET_ADDR_RANDOM for a generated address. Apply
pending administrative policy before open registers the station address,
because the policy worker can be waiting for RTNL while open holds it.
PF policy can still change after the refresh. If the PF skips every
station DELETE and rejects the ADD as not permitted, refresh policy
and retry once if it selects a different address. Keep the existing
recovery path when a reply indicates partial application or the final
state is uncertain. Use the same bounded retry on internal reopen.
Install the station address during open and remove it during an ordinary
stop. Quiesce and purge administrative-MAC work around remove-time channel
teardown. At reset and removal boundaries, use VF_UNREGISTER or fresh
registration as the protocol cleanup boundary. The PF is required to
discard VF-requested state before replying. The deployed async PF attempts
this cleanup but does not propagate every hardware-delete failure, so its
ACK is not independent hardware cleanup proof. The later PF activation
series must implement the cleanup and error-handling contract.
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
drivers/net/ethernet/cisco/enic/enic.h | 17 +
drivers/net/ethernet/cisco/enic/enic_admin.c | 2 +
drivers/net/ethernet/cisco/enic/enic_dev.c | 11 +
drivers/net/ethernet/cisco/enic/enic_dev.h | 1 +
drivers/net/ethernet/cisco/enic/enic_main.c | 643 ++++++++++++++++++++++++++-
drivers/net/ethernet/cisco/enic/enic_mbox.c | 30 ++
6 files changed, 697 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 2c494c8ae23d..7f1367de6611 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -360,6 +360,9 @@ struct enic {
spinlock_t vf_link_state_lock;
enum enic_vf_link_state vf_link_state;
bool vf_link_running;
+ /* Last station address which may still be installed at the PF. */
+ u8 vf_station_addr[ETH_ALEN] __aligned(2);
+ bool vf_station_addr_valid;
/* MBOX protocol state — mbox_lock serializes admin WQ sends */
struct mutex mbox_lock;
@@ -376,6 +379,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;
@@ -509,6 +522,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 9c4b94a94980..a2186f65c74a 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,501 @@ static int enic_set_mac_addr(struct net_device *netdev, char *addr)
return 0;
}
+static void enic_vf_station_recovery_required(struct enic *enic)
+{
+ enic_mbox_vf_require_reconnect(enic);
+}
+
+static void enic_vf_station_addr_set(struct enic *enic, const u8 *addr)
+{
+ ether_addr_copy(enic->vf_station_addr, addr);
+ enic->vf_station_addr_valid = true;
+}
+
+static int enic_vf_keep_nonstation_sync(struct net_device *netdev,
+ const u8 *addr)
+{
+ struct enic *enic = netdev_priv(netdev);
+
+ if (!ether_addr_equal(addr, enic->vf_station_addr))
+ return -ENOENT;
+ if (WARN_ON_ONCE(!enic->uc_count))
+ return 0;
+ enic->uc_count--;
+
+ return 0;
+}
+
+static void enic_vf_station_sync_reset(struct enic *enic)
+{
+ if (!enic->vf_station_addr_valid)
+ return;
+
+ /* The PF keys its MAC ledger by address. A station entry is also the
+ * receive filter for that address and must not retain a second core
+ * synchronization reference which could later delete the station.
+ */
+ netif_addr_lock_bh(enic->netdev);
+ __dev_uc_unsync(enic->netdev, enic_vf_keep_nonstation_sync);
+ netif_addr_unlock_bh(enic->netdev);
+}
+
+static int enic_vf_station_addr_del(struct enic *enic)
+{
+ int err;
+
+ if (!enic->vf_station_addr_valid)
+ return 0;
+
+ err = enic_mbox_vf_add_del_mac(enic, enic->vf_station_addr,
+ false, true);
+ if (!err) {
+ enic->vf_station_addr_valid = false;
+ } else if (READ_ONCE(enic->mbox_tx_poisoned)) {
+ enic_mbox_vf_link_state_set_running(enic, false);
+ } else if (err == -EACCES) {
+ /* A definitive rejected DELETE leaves an unrequested station
+ * filter installed. Fresh registration is the cleanup boundary.
+ */
+ enic_vf_station_recovery_required(enic);
+ }
+
+ return err;
+}
+
+/* End every replacement with an equal-address DEL+ADD pair. A bare ADD could
+ * report DUPLICATE for a secondary exact filter without applying the current
+ * station-address policy. If another station is tracked, delete it first in
+ * the same compound request.
+ */
+static int enic_vf_station_addr_replace(struct enic *enic, const u8 *addr,
+ bool *policy_rejected)
+{
+ struct enic_mac_addr macs[3] = {};
+ bool all_deletes_skipped = true;
+ bool deletes_converged = true;
+ u16 num_macs = 0;
+ unsigned int i;
+ u16 result;
+ int err;
+
+ if (policy_rejected)
+ *policy_rejected = false;
+
+ if (enic->vf_station_addr_valid &&
+ !ether_addr_equal(enic->vf_station_addr, addr)) {
+ ether_addr_copy(macs[num_macs].addr, enic->vf_station_addr);
+ macs[num_macs++].flags =
+ cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
+ }
+ ether_addr_copy(macs[num_macs].addr, addr);
+ macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
+ ether_addr_copy(macs[num_macs].addr, addr);
+ macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_ADD |
+ ENIC_MAC_ADDR_FLAG_STATION);
+
+ err = enic_mbox_vf_add_del_macs(enic, macs, num_macs);
+ if (err) {
+ if (READ_ONCE(enic->mbox_tx_poisoned))
+ enic_mbox_vf_link_state_set_running(enic, false);
+ return err;
+ }
+
+ for (i = 0; i < num_macs - 1; i++) {
+ result = le16_to_cpu(macs[i].flags) &
+ ENIC_MAC_ADDR_FLAG_REPLY_MASK;
+ if (result != ENIC_MAC_ADDR_FLAG_SKIPPED)
+ all_deletes_skipped = false;
+ if (result && result != ENIC_MAC_ADDR_FLAG_NOT_FOUND)
+ deletes_converged = false;
+ }
+ result = le16_to_cpu(macs[num_macs - 1].flags) &
+ ENIC_MAC_ADDR_FLAG_REPLY_MASK;
+ if (deletes_converged && !result)
+ return 0;
+
+ /* A policy-rejected ADD can be reported with all preceding DELETEs
+ * skipped. No operation changed state in that coherent result tuple.
+ */
+ if (all_deletes_skipped && result) {
+ if (policy_rejected)
+ *policy_rejected =
+ result == ENIC_MAC_ADDR_FLAG_NOT_PERMITTED;
+ if (result & (ENIC_MAC_ADDR_FLAG_DUPLICATE |
+ ENIC_MAC_ADDR_FLAG_PERMANENT_MASK))
+ return -EACCES;
+ return -EIO;
+ }
+
+ /* After any other partial or contradictory result, the VF does not know
+ * which station address the PF kept. Re-register before accepting traffic.
+ */
+ enic_vf_station_recovery_required(enic);
+ for (i = 0; i < num_macs; i++)
+ if (le16_to_cpu(macs[i].flags) &
+ ENIC_MAC_ADDR_FLAG_PERMANENT_MASK)
+ return -EACCES;
+
+ return -EIO;
+}
+
+static void enic_vf_admin_mac_cache_selected(struct enic *enic,
+ const u8 *addr)
+{
+ /* A zero administrative policy delegates the operational address to
+ * the VF. Preserve a successful user selection across reconnects.
+ */
+ spin_lock_bh(&enic->vf_admin_mac_lock);
+ if (is_zero_ether_addr(enic->vf_admin_mac)) {
+ ether_addr_copy(enic->vf_admin_mac_random_addr, addr);
+ enic->vf_admin_mac_random_valid = true;
+ }
+ spin_unlock_bh(&enic->vf_admin_mac_lock);
+}
+
+static void enic_vf_admin_mac_work(struct work_struct *work)
+{
+ struct enic *enic = container_of(to_delayed_work(work), struct enic,
+ vf_admin_mac_work);
+ u8 policy[ETH_ALEN];
+ 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, NULL);
+ station_installed = !err;
+ } else if (enic->vf_station_addr_valid &&
+ !ether_addr_equal(enic->vf_station_addr, selected)) {
+ mutated = true;
+ err = enic_vf_station_addr_del(enic);
+ station_installed = !err;
+ } else {
+ station_installed = true;
+ }
+ if (err)
+ goto unlock;
+
+ spin_lock_bh(&enic->vf_admin_mac_lock);
+ if (!enic->vf_admin_mac_pending ||
+ !enic->vf_admin_mac_work_enabled ||
+ enic->vf_admin_mac_generation != generation) {
+ stale = true;
+ /* If policy changed while the request was running, the completed
+ * station change may no longer match it. Record recovery while holding
+ * vf_admin_mac_lock, which also protects VF worker shutdown. Teardown
+ * therefore either suppresses the update or sees it first, and already
+ * uses unregister/register to clear old state.
+ */
+ if (mutated && enic->vf_admin_mac_work_enabled)
+ enic_vf_station_recovery_required(enic);
+ } else {
+ enic->vf_admin_mac_pending = false;
+ enic->vf_admin_mac_retries = 0;
+ enic->vf_admin_mac_recovery_attempted = false;
+ if (!zero_policy)
+ enic->vf_admin_mac_random_valid = false;
+ }
+ spin_unlock_bh(&enic->vf_admin_mac_lock);
+ if (stale)
+ goto unlock;
+
+ changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
+ enic_vf_station_sync_reset(enic);
+ 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_vf_station_addr_open(struct enic *enic)
+{
+ struct net_device *netdev = enic->netdev;
+ u8 requested[ETH_ALEN] __aligned(2);
+ bool policy_rejected;
+ int err;
+
+ ether_addr_copy(requested, netdev->dev_addr);
+ err = enic_vf_station_addr_replace(enic, requested, &policy_rejected);
+ if (!policy_rejected || !READ_ONCE(enic->vf_registered) ||
+ READ_ONCE(enic->mbox_send_disabled))
+ return err;
+
+ /* PF policy can change after the last refresh, with its notification
+ * still in flight. A clean rejection permits one attempt at the new MAC.
+ */
+ err = enic_vf_admin_mac_refresh(enic);
+ if (err)
+ return err;
+ if (ether_addr_equal(requested, netdev->dev_addr))
+ return -EACCES;
+
+ return enic_vf_station_addr_replace(enic, netdev->dev_addr, NULL);
+}
+
static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
{
struct enic *enic = netdev_priv(netdev);
@@ -1071,6 +1569,53 @@ static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
char *addr = saddr->sa_data;
int err;
+ if (enic_is_sriov_vf_v2(enic)) {
+ if (!is_valid_ether_addr(addr))
+ return -EADDRNOTAVAIL;
+
+ spin_lock_bh(&enic->vf_admin_mac_lock);
+ err = is_valid_ether_addr(enic->vf_admin_mac) &&
+ !ether_addr_equal(enic->vf_admin_mac, addr);
+ spin_unlock_bh(&enic->vf_admin_mac_lock);
+ if (err)
+ return -EPERM;
+ if (ether_addr_equal(addr, netdev->dev_addr))
+ return 0;
+
+ if (READ_ONCE(enic->datapath_open) &&
+ !READ_ONCE(enic->vf_registered))
+ return -ENODEV;
+
+ /* An internal reset keeps IFF_UP set while its failed reopen leaves
+ * the datapath closed. Cache the requested address in that state; the
+ * next successful open installs it together with the datapath.
+ */
+ if (!READ_ONCE(enic->datapath_open)) {
+ err = enic_set_mac_addr(netdev, addr);
+ if (!err)
+ enic_vf_admin_mac_cache_selected(enic, addr);
+ return err;
+ }
+
+ /* Keep the old software address visible until the complete station
+ * replacement proves convergence.
+ */
+ err = enic_vf_station_addr_replace(enic, addr, NULL);
+ if (err)
+ return err;
+
+ enic_vf_station_sync_reset(enic);
+ err = enic_set_mac_addr(netdev, addr);
+ if (!err) {
+ enic_vf_station_addr_set(enic, addr);
+ enic_vf_station_sync_reset(enic);
+ enic_vf_admin_mac_cache_selected(enic, addr);
+ netif_rx_mode_schedule_update(netdev);
+ }
+
+ return err;
+ }
+
if (netif_running(enic->netdev)) {
err = enic_dev_del_station_addr(enic);
if (err)
@@ -1737,6 +2282,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 +2380,40 @@ static int __enic_open(struct net_device *netdev,
if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
enic_dev_add_station_addr(enic);
+ if (enic_is_sriov_vf_v2(enic)) {
+ if (!READ_ONCE(enic->vf_registered)) {
+ netdev_err(netdev, "VF is not registered with its PF\n");
+ err = -ENODEV;
+ goto err_out_disable_wq;
+ }
+
+ /* A pending administrative-MAC change may not have reached
+ * dev_addr yet because the refresh worker backs off while RTNL is
+ * held. Apply the current PF policy now so a stale station
+ * address is not registered (the PF would reject it with -EACCES).
+ */
+ if (READ_ONCE(enic->vf_admin_mac_pending)) {
+ err = enic_vf_admin_mac_refresh(enic);
+ if (err) {
+ netdev_err(netdev,
+ "Failed to apply pending admin MAC before open: %d\n",
+ err);
+ goto err_out_disable_wq;
+ }
+ }
+
+ err = enic_vf_station_addr_open(enic);
+ if (err) {
+ netdev_err(netdev,
+ "Failed to register VF station address: %d\n",
+ err);
+ goto err_out_disable_wq;
+ }
+ enic_vf_station_addr_set(enic, netdev->dev_addr);
+ enic_vf_station_sync_reset(enic);
+ vf_mac_added = true;
+ }
+
enic_set_rx_mode(netdev);
netif_tx_wake_all_queues(netdev);
@@ -1897,6 +2477,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 +2529,7 @@ static int enic_open(struct net_device *netdev)
}
/* rtnl lock is held, process context */
-static int __enic_stop(struct net_device *netdev)
+static int __enic_stop(struct net_device *netdev, bool remove_vf_station)
{
struct enic *enic = netdev_priv(netdev);
unsigned int i;
@@ -1974,6 +2563,15 @@ static int __enic_stop(struct net_device *netdev)
for (i = 0; i < enic->wq_count; i++)
napi_disable(&enic->napi[enic_cq_wq(enic, i)]);
netif_tx_disable(netdev);
+ if (remove_vf_station && enic_is_sriov_vf_v2(enic) &&
+ 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 +2617,7 @@ static int __enic_stop(struct net_device *netdev)
static int enic_stop(struct net_device *netdev)
{
- return __enic_stop(netdev);
+ return __enic_stop(netdev, true);
}
static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
@@ -2483,9 +3081,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 ||
@@ -2504,6 +3114,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
@@ -2603,7 +3214,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);
@@ -2744,7 +3355,7 @@ static void enic_hang_reset(struct enic *enic, bool mailbox_recovery)
WRITE_ONCE(enic->vf_registered, false);
}
if (READ_ONCE(enic->datapath_open))
- stop_err = __enic_stop(enic->netdev);
+ stop_err = __enic_stop(enic->netdev, false);
if (enic_is_sriov_vf_v2(enic))
enic_mbox_vf_link_state_reset(enic);
if (stop_err || enic_control_dma_unresolved(enic)) {
@@ -3692,6 +4303,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
@@ -3723,6 +4337,14 @@ 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;
+ }
+ /* Record the initial address while preserving how it was assigned. */
+ ether_addr_copy(netdev->perm_addr, netdev->dev_addr);
}
netif_set_real_num_tx_queues(netdev, enic->wq_count);
@@ -3849,6 +4471,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;
@@ -3921,9 +4545,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);
@@ -3942,6 +4569,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 5afb45033772..4795e8cefe8e 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
* [PATCH net-next v4 6/6] enic: configure V2 VF receive mode over mailbox
2026-11-30 13:58 [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
` (4 preceding siblings ...)
2026-11-30 13:58 ` [PATCH net-next v4 5/6] enic: manage V2 VF station and administrative MAC Satish Kharat
@ 2026-11-30 13:58 ` Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
5 siblings, 1 reply; 12+ messages in thread
From: Satish Kharat @ 2026-11-30 13:58 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Willem de Bruijn
Cc: netdev, linux-kernel, Sesidhar Baddela, Aravind Dhanasekaran,
Reese Faucette, Satish Kharat
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. Send stale DELETEs before new ADDs in one
exact-filter batch and send packet-filter mode updates separately.
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 the finite exact-filter subset even when broad
coverage is required or denied, leaving overflow entries unsynchronized
for later convergence.
Use the validated applied mask to order broad-mode transitions. Request
newly needed broad coverage before exact-filter work and withdraw stale
broad coverage before installing its finite replacement. If a command
fails while obsolete broad coverage may remain, require reconnect unless
recovery is already pending or the send queue is poisoned. A validated
policy denial of the new broad mode leaves degraded coverage and still
allows withdrawal of the old mode. Report policy denials during open and
runtime updates.
Track detailed per-address results so idempotent outcomes converge and
stable ADD policy denials do not consume the retry budget. Preserve an
installed-filter counter inconsistency across later ADD results. Compatible
PFs reject whole requests before applying operations and report individual
operation failures separately. Require fresh registration after a request-
wide -EIO involving DELETE, retiring stale filters from the previous
snapshot. Keep local pre-submit and add-only rejections on the normal
retry path. Keep the station address out of both secondary address lists.
Exclude an all-zero MAC from requested counts and operation collection
before projecting exact-filter occupancy. The PF rejects that address as
INVALID, so reserving capacity for it would crowd out a later valid
address on every update.
Require the individual/group bit to match the netdev address-list class
before counting an address or collecting its operations. The PF tracks
a single filter per raw MAC. Counting the same MAC in both lists can
reserve capacity twice and removing one reference can delete the filter
while the other list still considers it synchronized.
Select the asynchronous netdev operations only for V2 VFs. Schedule
receive-mode replay after successful internal reopen on reset, hang reset,
or a direct MTU change.
Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
drivers/net/ethernet/cisco/enic/enic.h | 3 +
drivers/net/ethernet/cisco/enic/enic_main.c | 493 +++++++++++++++++++++++++++-
2 files changed, 484 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/cisco/enic/enic.h b/drivers/net/ethernet/cisco/enic/enic.h
index 7f1367de6611..d148a75ce0aa 100644
--- a/drivers/net/ethernet/cisco/enic/enic.h
+++ b/drivers/net/ethernet/cisco/enic/enic.h
@@ -398,6 +398,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 a2186f65c74a..4a9b4bf9e16b 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)
@@ -1653,17 +1655,419 @@ static int enic_set_mac_address(struct net_device *netdev, void *p)
return enic_dev_add_station_addr(enic);
}
+static u16 enic_rx_mode_to_pkt_filter(struct net_device *netdev,
+ unsigned int uc_count,
+ unsigned int mc_count)
+{
+ u16 flags = CMD_PFILTER_DIRECTED;
+
+ if (netdev->flags & IFF_MULTICAST)
+ flags |= CMD_PFILTER_MULTICAST;
+ if (netdev->flags & IFF_BROADCAST)
+ flags |= CMD_PFILTER_BROADCAST;
+ if ((netdev->flags & IFF_PROMISC) ||
+ uc_count > ENIC_UNICAST_PERFECT_FILTERS)
+ flags |= CMD_PFILTER_PROMISCUOUS;
+ if ((netdev->flags & IFF_ALLMULTI) ||
+ mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
+ flags |= CMD_PFILTER_ALL_MULTICAST;
+
+ return flags;
+}
+
+/* Deployed async PFs count the station MAC in the 32-entry UC table. */
+static bool enic_vf_uc_needs_promisc(unsigned int uc_count)
+{
+ return uc_count > ENIC_UNICAST_PERFECT_FILTERS - 1;
+}
+
+static int enic_vf_set_pkt_filter(struct enic *enic, u16 flags,
+ u16 *applied_flags)
+{
+ u16 applied;
+ int err;
+
+ /* The PF can change trust policy independently and thereby withdraw
+ * broad modes. Always refresh those requests so the returned applied
+ * flags remain authoritative. The other modes are not trust-gated and
+ * can be reused for ordinary address-list churn.
+ */
+ if (!(flags & (CMD_PFILTER_PROMISCUOUS |
+ CMD_PFILTER_ALL_MULTICAST)) &&
+ enic->vf_pkt_filter_valid &&
+ enic->vf_pkt_filter_requested == flags) {
+ if (applied_flags)
+ *applied_flags = enic->vf_pkt_filter_applied;
+ return 0;
+ }
+
+ err = enic_mbox_vf_set_pkt_filter(enic,
+ !!(flags & CMD_PFILTER_DIRECTED),
+ !!(flags & CMD_PFILTER_MULTICAST),
+ !!(flags & CMD_PFILTER_BROADCAST),
+ !!(flags & CMD_PFILTER_PROMISCUOUS),
+ !!(flags & CMD_PFILTER_ALL_MULTICAST),
+ &applied);
+ if (err)
+ return err;
+
+ enic->vf_pkt_filter_requested = flags;
+ enic->vf_pkt_filter_applied = applied;
+ enic->vf_pkt_filter_valid = true;
+ if (applied_flags)
+ *applied_flags = applied;
+
+ return 0;
+}
+
+static void enic_vf_report_pkt_filter_denial(struct net_device *netdev,
+ u16 requested, u16 applied)
+{
+ if ((requested & CMD_PFILTER_PROMISCUOUS) &&
+ !(applied & CMD_PFILTER_PROMISCUOUS))
+ netdev_dbg(netdev, "PF policy denied promiscuous receive mode\n");
+ if ((requested & CMD_PFILTER_ALL_MULTICAST) &&
+ !(applied & CMD_PFILTER_ALL_MULTICAST))
+ netdev_dbg(netdev,
+ "PF policy denied all-multicast receive mode\n");
+}
+
+struct enic_vf_mac_op {
+ struct netdev_hw_addr *ha;
+ unsigned int *filter_count;
+};
+
+static bool
+enic_vf_secondary_addr_valid(const struct enic *enic,
+ const struct netdev_hw_addr *ha)
+{
+ u8 type = is_multicast_ether_addr(ha->addr) ?
+ NETDEV_HW_ADDR_T_MULTICAST : NETDEV_HW_ADDR_T_UNICAST;
+
+ /* The PF stores one exact filter per MAC. Admit it from the list
+ * matching its Ethernet address class, and leave the station separate.
+ */
+ return ha->type == type && !is_zero_ether_addr(ha->addr) &&
+ !(enic->vf_station_addr_valid &&
+ ether_addr_equal(ha->addr, enic->vf_station_addr));
+}
+
+static unsigned int
+enic_vf_addr_list_count(const struct enic *enic,
+ const struct netdev_hw_addr_list *list)
+{
+ const struct netdev_hw_addr *ha;
+ unsigned int count = 0;
+
+ netdev_hw_addr_list_for_each(ha, list)
+ if (ha->refcount > ha->sync_cnt &&
+ enic_vf_secondary_addr_valid(enic, ha))
+ count++;
+
+ return count;
+}
+
+static int enic_vf_collect_mac_ops(struct enic *enic,
+ struct netdev_hw_addr_list *list,
+ bool add,
+ unsigned int *filter_count,
+ unsigned int *projected_count,
+ unsigned int max_filters,
+ struct enic_mac_addr *macs,
+ struct enic_vf_mac_op *ops,
+ u16 *num_ops)
+{
+ struct netdev_hw_addr *ha;
+ u16 pos = *num_ops;
+
+ netdev_hw_addr_list_for_each(ha, list) {
+ if (!enic_vf_secondary_addr_valid(enic, ha))
+ continue;
+ if (add) {
+ if (ha->sync_cnt || *projected_count >= max_filters)
+ continue;
+ } else {
+ if (!ha->sync_cnt || ha->refcount != ha->sync_cnt)
+ continue;
+ WARN_ON_ONCE(!*projected_count);
+ }
+ if (pos == ENIC_MBOX_MAX_MAC_OPS)
+ return -E2BIG;
+
+ ether_addr_copy(macs[pos].addr, ha->addr);
+ macs[pos].flags = add ?
+ cpu_to_le16(ENIC_MAC_ADDR_FLAG_ADD) : 0;
+ ops[pos].ha = ha;
+ ops[pos].filter_count = filter_count;
+ pos++;
+ if (add)
+ (*projected_count)++;
+ else if (*projected_count)
+ (*projected_count)--;
+ }
+
+ *num_ops = pos;
+ return 0;
+}
+
+static int enic_vf_sync_mac_filters(struct enic *enic,
+ struct netdev_hw_addr_list *uc,
+ struct netdev_hw_addr_list *mc)
+{
+ unsigned int projected_mc = enic->mc_count;
+ unsigned int projected_uc = enic->uc_count;
+ struct enic_vf_mac_op *ops;
+ struct enic_mac_addr *macs;
+ bool permanent_add = false;
+ bool retryable_add = false;
+ bool has_delete = false;
+ bool reconnect = false;
+ u16 num_ops = 0;
+ unsigned int i;
+ int err = 0;
+
+ /* A class can contribute at most its installed perfect filters as
+ * deletes and its finite perfect-filter limit as adds. Keep the wire
+ * batch large enough for both classes so an update always fits in one
+ * transaction and -E2BIG remains only a defensive state-corruption
+ * check.
+ */
+ BUILD_BUG_ON(ENIC_MBOX_MAX_MAC_OPS <
+ 2 * (ENIC_UNICAST_PERFECT_FILTERS - 1 +
+ ENIC_MULTICAST_PERFECT_FILTERS));
+
+ macs = kcalloc(ENIC_MBOX_MAX_MAC_OPS, sizeof(*macs), GFP_KERNEL);
+ if (!macs)
+ return -ENOMEM;
+ ops = kcalloc(ENIC_MBOX_MAX_MAC_OPS, sizeof(*ops), GFP_KERNEL);
+ if (!ops) {
+ err = -ENOMEM;
+ goto free_macs;
+ }
+
+ /* Collect all stale deletes before any add. Projected occupancy reserves
+ * only replies which could fit after those deletes; actual counts change
+ * below only for successful per-operation results.
+ */
+ err = enic_vf_collect_mac_ops(enic, uc, false, &enic->uc_count,
+ &projected_uc, 0,
+ macs, ops, &num_ops);
+ if (err)
+ goto free_ops;
+ err = enic_vf_collect_mac_ops(enic, mc, false, &enic->mc_count,
+ &projected_mc, 0,
+ macs, ops, &num_ops);
+ if (err)
+ goto free_ops;
+ has_delete = num_ops != 0;
+
+ err = enic_vf_collect_mac_ops(enic, uc, true, &enic->uc_count,
+ &projected_uc,
+ ENIC_UNICAST_PERFECT_FILTERS - 1,
+ macs, ops, &num_ops);
+ if (err)
+ goto free_ops;
+ err = enic_vf_collect_mac_ops(enic, mc, true, &enic->mc_count,
+ &projected_mc,
+ ENIC_MULTICAST_PERFECT_FILTERS,
+ macs, ops, &num_ops);
+ if (err || !num_ops)
+ goto free_ops;
+
+ /* Keep exact-filter operations in one MAC request. Packet-filter mode
+ * transitions may issue separate requests in the same callback.
+ */
+ err = enic_mbox_vf_add_del_macs(enic, macs, num_ops);
+ if (err) {
+ /* Supported PFs reject a whole request before applying operations.
+ * A rejected DELETE batch leaves stale acceptance from the previous
+ * snapshot. Fresh registration retires it; ADD-only rejections retry.
+ */
+ if (err == -EIO && has_delete &&
+ !READ_ONCE(enic->mbox_tx_poisoned) &&
+ !READ_ONCE(enic->vf_mbox_reconnect_required))
+ enic_mbox_vf_require_reconnect(enic);
+ goto free_ops;
+ }
+
+ for (i = 0; i < num_ops; i++) {
+ u16 flags = le16_to_cpu(macs[i].flags);
+ bool add = flags & ENIC_MAC_ADDR_FLAG_ADD;
+
+ if (flags & ENIC_MAC_ADDR_FLAG_SKIPPED) {
+ if (add)
+ retryable_add = true;
+ else
+ reconnect = true;
+ continue;
+ }
+ if (flags & ENIC_MAC_ADDR_FLAG_PERMANENT_MASK) {
+ if (add)
+ permanent_add = true;
+ else
+ reconnect = true;
+ continue;
+ }
+
+ if (add) {
+ ops[i].ha->sync_cnt++;
+ ops[i].ha->refcount++;
+ (*ops[i].filter_count)++;
+ } else {
+ ops[i].ha->sync_cnt--;
+ ops[i].ha->refcount--;
+ if (WARN_ON_ONCE(!*ops[i].filter_count))
+ err = -EIO;
+ else
+ (*ops[i].filter_count)--;
+ }
+ }
+
+ /* A failed DELETE can leave hardware accepting an address no longer in
+ * the requested list. Registration is the fail-closed cleanup boundary.
+ * A skipped ADD changes no acceptance state and can use the bounded core
+ * retry path. Permanent ADD denials remain stable policy results.
+ */
+ if (reconnect) {
+ enic_mbox_vf_require_reconnect(enic);
+ err = -EIO;
+ } else if (err != -EIO) {
+ /* Do not let a retryable or permanently-denied ADD overwrite an
+ * installed-filter counter inconsistency (-EIO) detected above.
+ */
+ if (retryable_add)
+ err = -EAGAIN;
+ else if (permanent_add)
+ err = -EACCES;
+ }
+
+free_ops:
+ kfree(ops);
+free_macs:
+ kfree(macs);
+ return err;
+}
+
+static int enic_set_vf_rx_mode(struct net_device *netdev,
+ struct netdev_hw_addr_list *uc,
+ struct netdev_hw_addr_list *mc)
+{
+ struct enic *enic = netdev_priv(netdev);
+ unsigned int uc_count = enic_vf_addr_list_count(enic, uc);
+ unsigned int mc_count = enic_vf_addr_list_count(enic, mc);
+ u16 flags = enic_rx_mode_to_pkt_filter(netdev, uc_count, mc_count);
+ bool uc_overflow = enic_vf_uc_needs_promisc(uc_count);
+ u16 broad_modes = CMD_PFILTER_PROMISCUOUS |
+ CMD_PFILTER_ALL_MULTICAST;
+ bool target_filter_updated = false;
+ bool broad_enable_needed;
+ bool broad_withdrawal;
+ u16 prefilter_flags;
+ bool filter_needed;
+ u16 applied_broad;
+ u16 applied_flags;
+ int err;
+
+ 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);
@@ -2283,9 +2687,13 @@ static int __enic_open(struct net_device *netdev,
{
struct enic *enic = netdev_priv(netdev);
bool vf_mac_added = false;
+ unsigned int vf_mc_count;
+ unsigned int vf_uc_count;
bool clear_cqs = false;
- unsigned int i;
+ u16 vf_filter_applied;
+ u16 vf_filter_flags;
int stop_err = 0;
+ unsigned int i;
int err, ret;
unsigned int max_pkt_len = netdev->mtu + VLAN_ETH_HLEN;
struct page_pool_params pp_params = {
@@ -2379,7 +2787,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");
@@ -2412,9 +2819,31 @@ static int __enic_open(struct net_device *netdev,
enic_vf_station_addr_set(enic, netdev->dev_addr);
enic_vf_station_sync_reset(enic);
vf_mac_added = true;
+
+ netif_addr_lock_bh(netdev);
+ vf_uc_count = enic_vf_addr_list_count(enic, &netdev->uc);
+ vf_mc_count = enic_vf_addr_list_count(enic, &netdev->mc);
+ netif_addr_unlock_bh(netdev);
+
+ vf_filter_flags = enic_rx_mode_to_pkt_filter(netdev,
+ vf_uc_count,
+ vf_mc_count);
+ if (enic_vf_uc_needs_promisc(vf_uc_count))
+ vf_filter_flags |= CMD_PFILTER_PROMISCUOUS;
+ err = enic_vf_set_pkt_filter(enic, vf_filter_flags,
+ &vf_filter_applied);
+ if (err) {
+ netdev_err(netdev,
+ "Failed to configure VF packet filter: %d\n",
+ err);
+ goto err_out_disable_wq;
+ }
+ enic_vf_report_pkt_filter_denial(netdev, vf_filter_flags,
+ vf_filter_applied);
}
- enic_set_rx_mode(netdev);
+ if (!enic_is_sriov_vf_v2(enic))
+ enic_set_rx_mode(netdev);
netif_tx_wake_all_queues(netdev);
@@ -2622,6 +3051,7 @@ static int enic_stop(struct net_device *netdev)
static int _enic_change_mtu(struct net_device *netdev, int new_mtu)
{
+ struct enic *enic = netdev_priv(netdev);
bool running = netif_running(netdev);
int err = 0;
@@ -2638,6 +3068,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;
@@ -3275,6 +3707,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
@@ -3412,6 +3850,8 @@ static void enic_hang_reset(struct enic *enic, bool mailbox_recovery)
netdev_err(enic->netdev,
"Failed to reopen datapath after hang reset: %d\n", err);
goto hang_reset_out;
+ } else if (reopen && enic_is_sriov_vf_v2(enic)) {
+ netif_rx_mode_schedule_update(enic->netdev);
}
/* A PF reopens its admin channel after the datapath and re-pushes link
@@ -3695,6 +4135,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,
@@ -4381,7 +4845,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;
@@ -4545,9 +5011,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 v4 2/6] enic: serialize V2 VF mailbox requests
2026-11-30 13:58 ` [PATCH net-next v4 2/6] enic: serialize V2 VF mailbox requests Satish Kharat
@ 2026-12-01 14:04 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 14:04 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
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 commit message describes a race that cannot happen at this
commit: "If two VF control paths issue requests at the same time, the…
- [Low] The commit message says the patch will "Clear pending state on
send failure so a later request cannot inherit it".
--
enic: serialize V2 VF mailbox requests
This commit adds a VF-only mutex, vf_mbox_request_lock. The mutex is held
from before a mailbox request is armed until its reply or timeout has
been consumed. The commit also rechecks vf_registered in
enic_mbox_vf_unregister() after taking the mutex, and clears the expected
reply state when a send fails.
> 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.
[Severity: Low]
Can two VF control paths actually issue requests at the same time at this
commit?
The only VF request senders are enic_mbox_vf_capability_check(),
enic_mbox_vf_register() and enic_mbox_vf_unregister() in enic_mbox.c.
Their callers in enic_main.c already appear to exclude each other:
- enic_admin_chan_reopen() is only called from enic_reset() and
enic_tx_hang_reset(). Both hold rtnl_lock() for the whole reset.
- Probe calls the capability check and register back to back. This
happens before INIT_WORK() for the reset works and before
register_netdev().
- enic_remove() calls disable_work_sync() on reset, tx_hang_reset and
change_mtu_work before it calls enic_mbox_vf_unregister(). The probe
error path is single threaded.
So the new recheck in enic_mbox_vf_unregister() does not seem to guard
against any overlap the current tree can produce:
enic_mbox_vf_request_start(enic);
if (!READ_ONCE(enic->vf_registered)) {
enic_mbox_vf_request_finish(enic);
return 0;
}
The mutex seems to become necessary later in the series. That is where
more enic_mbox_vf_request_start() users are added for the MAC add/del,
packet filter and recovery paths.
Could the commit message say this is preparation for those concurrent
request paths? Otherwise it may be read, or backported, as a standalone
race fix.
The comment above mbox_comp in struct enic in enic.h also still says:
/* MBOX request-reply state. Existing request callers allow only one
* request in flight. [ ... ]
Should that comment be updated together with the new
vf_mbox_request_lock?
> 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 registration
> in the unregister path after taking the mutex. Clear pending state on
> send failure so a later request cannot inherit it.
[Severity: Low]
Does "Clear pending state on send failure so a later request cannot
inherit it" describe new behavior? enic_mbox_send_msg_id() already clears
the armed state on its unlock path:
unlock:
if (err && reply_expected) {
spin_lock_bh(&enic->mbox_state_lock);
if (enic->mbox_expected_reply == expected_reply &&
enic->mbox_expected_msg_num == msg_num) {
enic->mbox_expected_reply = 0;
enic->mbox_expected_msg_num = 0;
}
spin_unlock_bh(&enic->mbox_state_lock);
}
That covers the two failures that can happen after arming: the
dma_mapping_error() -ENOMEM and the send -ETIMEDOUT.
The earlier exits are the -EINVAL payload size check, the -ENODEV check
for no channel or sends disabled, -ENOSPC, and the kmalloc() -ENOMEM.
All of them return before reply_expected is set, so no state was armed.
enic_mbox_vf_request_start() also zeroes mbox_expected_reply and
mbox_expected_msg_num before every request. Because of that, the clear
in enic_mbox_vf_request_abort() repeats what already happens:
> +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);
> +}
Could the commit message be reworded so this is not presented as a fix
for an inheritance problem?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-b4-enic-sriov-v2-vf-receive-control-v4-0-5858d5a9ecb1%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v4 3/6] enic: recover V2 VF mailbox after request failure
2026-11-30 13:58 ` [PATCH net-next v4 3/6] enic: recover V2 VF mailbox after request failure Satish Kharat
@ 2026-12-01 14:04 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 14:04 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
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 (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] The commit is titled and framed as V2 VF mailbox recovery, but
it changes the shared reset, stop and open paths of every ENIC device.
- [Medium] The RX quarantine is not armed for internal resets that are
not caused by a mailbox fault.
- [Medium] A mailbox fault that arrives while a recovery worker is
running is dropped if it also makes that recovery fail.
- [Low] At this commit, several new comments describe behaviour that only
later patches add.
- [Low] The schedule_reset_on_failure parameter of __enic_open() and the
helper enic_schedule_datapath_reset() are dead code.
Pre-existing issues:
- [Low] When a generic WQ/RQ disable fails in __enic_stop(), the code
jumps to stop_failed after datapath_open has already been cleared.
--
enic: recover V2 VF mailbox after request failure
This patch adds V2 VF mailbox recovery after a lost reply or a
send-completion timeout. Recovery runs on a dedicated work item and shares
the hang-reset sequence with the Tx watchdog. The patch also reworks the
shared open, stop and reset paths: it tracks datapath_open, takes
devcmd_lock around the reset polls, issues runtime CMD_INIT after soft
reset, and detaches the netdev when recovery fails.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index dde9098357d16..9c4b94a949809 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
[ ... ]
> @@ -1743,6 +1760,37 @@ static int enic_open(struct net_device *netdev)
> enic_admin_channel_is_quarantined(enic))
> return -EBUSY;
>
[ ... ]
> + 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;
[Severity: Low]
Can this branch ever call enic_schedule_datapath_reset()?
The quarantined check just above returns -EBUSY before this block runs. So
enic_admin_channel_close() is only reached here with the channel LIVE.
>From LIVE, enic_admin_channel_close() ends in one of two states. It is
QUARANTINED if the WQ or RQ disable fails. Otherwise it is DOWN, through
enic_admin_channel_release(). The state enum has only DOWN, LIVE and
QUARANTINED.
So "state != DOWN" implies quarantined here, and the inner condition looks
unreachable. That would make enic_schedule_datapath_reset() dead code, and
the schedule_reset_on_failure flag passed through enic_open(), enic_reset()
and enic_hang_reset() would have no effect. Could both be dropped? This is
unchanged at the end of the series.
> + }
> + }
[ ... ]
> @@ -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);
> +
[Severity: Medium]
The subject limits this to V2 VF mailbox recovery. Several changes here
affect every ENIC device and fix older bugs. Should they be split out with
their own Fixes: tags?
Compared with the baseline, these look like standalone fixes:
- The datapath_open guard. In the baseline, a failed enic_open() in
enic_reset() could leave IFF_UP set. A later dev_close() then ran
enic_stop() and called napi_disable() a second time.
- Moving enic_free_intr() before the queue disables. Baseline
enic_stop() returned before freeing the IRQs when vnic_wq_disable() or
vnic_rq_disable() failed.
- The devcmd_lock in enic_dev_soft_reset_start(),
enic_dev_soft_reset_done() and enic_dev_hang_reset_start(). Baseline
enic_dev_wait() called the reset helpers without the lock, so they
could collide with CMD_STATS_DUMP.
These change behaviour for PFs and other non-VF functions:
- enic_reset() now issues CMD_INIT through enic_vnic_dev_init() after
SOFT_RESET for every non-dynamic function.
- A failed soft reset, hang reset, INIT or queue stop now calls
enic_detach_after_recovery_failure() on any ENIC device. The driver
has no netif_device_attach(), so only a rebind recovers.
- The soft reset fallback in vnic_dev_hang_reset() no longer runs
vnic_dev_init() inline. INIT is now deferred, and dynamic vNICs do not
get it at all.
Several smaller, unrelated changes are also included:
- netif_addr_lock_bh() in enic_reset_addr_lists()
- the VF ACK worker
- CQ VLAN sender filtering in enic_admin_rq_cq_service()
- the netif_device_present() checks in enic_set_ringparam()
With everything in one commit, stable trees cannot take the hang, IRQ-leak
or devcmd fixes on their own. A bisect of a PF reset regression would also
land on a commit whose subject says it only touches V2 VFs.
[ ... ]
> @@ -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;
> +}
[Severity: Low]
This isn't a bug introduced by this patch, but the stop_failed path leaves
the datapath resources allocated, and nothing frees them later.
datapath_open was already cleared at the top of __enic_stop(). A later
dev_close() or unregister_netdev()->enic_stop() therefore returns 0 at
once. These calls never run:
- enic_dev_notify_unset()
- vnic_wq_clean()
- vnic_rq_clean() with page_pool_destroy()
- vnic_cq_clean()
__enic_open() behaves the same way on its late unwind path when stop_err
is set. The TX buffers and the pools of RQs that failed to disable are
kept.
Baseline enic_stop() also returned early on the same error, and the commit
message calls this separate work. Keeping buffers for a queue that may
still be running avoids DMA into freed memory, so this may be deliberate.
Is a follow-up planned for these resources?
[ ... ]
> @@ -2215,12 +2422,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)
> {
[Severity: Low]
The header comment of enic_admin_chan_reopen() still says it re-establishes
the channel "after a reset has re-created the data path". For V2 VFs it now
runs before the datapath reopen, from enic_reset(), enic_hang_reset() and
__enic_open(). The comment also doesn't describe the new int return. Could
it be updated?
Some other new comments describe behaviour that only later patches in the
series add:
- The late check in __enic_open() says "while station and receive
policy were being programmed". At this commit, VF station install is
skipped and enic_set_rx_mode() uses devcmds.
- enic_reset() and enic_hang_reset() say "A V2 VF needs PF registration
before enic_open() can install its station address."
- enic_mbox_wait_reply() says the reconnect decision is "an
operation-specific decision made by the caller". No caller makes that
decision yet.
These become accurate after "enic: manage V2 VF station and administrative
MAC" and "enic: configure V2 VF receive mode over mailbox". The
enic_admin_chan_reopen() header comment is still stale at the end of the
series.
[ ... ]
> @@ -2271,135 +2511,342 @@ static void enic_admin_chan_reopen(struct enic *enic)
[ ... ]
> +static bool enic_vf_mbox_recovery_finish(struct enic *enic, bool succeeded)
> +{
> + bool restart;
> +
> + spin_lock_bh(&enic->mbox_state_lock);
> + /* Restart only for a fault still outstanding after recovery. Fresh
> + * registration may already have consumed a fault from the old channel.
> + * A failed handshake remains quarantined for an external recovery event.
> + */
> + restart = succeeded &&
> + (READ_ONCE(enic->vf_mbox_reconnect_required) ||
> + READ_ONCE(enic->mbox_tx_poisoned));
> + enic->vf_mbox_recovery_active = false;
> + spin_unlock_bh(&enic->mbox_state_lock);
> +
> + return restart;
> +}
[Severity: Medium]
What happens to a mailbox fault that arrives while recovery is running and
also makes that recovery fail?
enic_vf_mbox_recovery_work()
enic_hang_reset(enic, true)
enic_vf_mbox_recovery_begin() /* vf_mbox_recovery_active = true */
enic_admin_chan_reopen()
enic_admin_channel_open() /* channel is LIVE again */
enic_mbox_vf_capability_check() / enic_mbox_vf_register()
Meanwhile, on the admin RX path:
enic_admin_msg_enqueue() /* kmalloc failure or backlog full */
enic_admin_rx_lost()
enic_mbox_vf_require_reconnect()
vf_mbox_fault_generation++
enic_mbox_vf_kick_recovery() /* recovery_active, not scheduled */
A bad length, truncation, bad FCS or a send timeout in
enic_mbox_send_msg_id() follows the same path.
enic_admin_chan_reopen() then returns -EAGAIN from the generation check, or
the late check in __enic_open() returns -EIO. Either way,
enic_vf_mbox_recovery_finish(enic, false) returns restart == false, and
nothing is scheduled.
The VF is left in this state:
- IFF_UP still set
- datapath stopped and IRQs freed
- admin channel DOWN
- carrier off
- netdev still attached
None of the automatic recovery triggers can fire in this state. The Tx
watchdog needs carrier, the error IRQ has been freed, and new mailbox
faults need a LIVE channel. Only a manual down/up seems to recover it.
Should a suppressed kick be remembered, or should finish() restart when
vf_mbox_fault_generation changed during the recovery? The -EAGAIN return
implies a retry that never happens. This is unchanged at the end of the
series.
[ ... ]
> diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
> index d1b6f13c8002f..3579d2980a246 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c
[ ... ]
> @@ -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);
[Severity: Medium]
Is vf_rx_quarantined armed again for internal resets that weren't caused by
a mailbox fault?
It is set to true in only three places:
- this first-init branch
- the send-timeout branch of enic_mbox_send_msg_id()
- enic_mbox_vf_mark_reconnect_locked()
The reinit branch used by enic_admin_chan_reopen() leaves it at the false
value from the last successful open.
Take a queue-error reset (enic->reset) or a Tx-timeout reset
(tx_hang_reset) on a V2 VF:
enic_reset()
enic_admin_channel_close() /* vf_registered = false */
__enic_stop()
enic_admin_chan_reopen()
enic_mbox_init() /* reinit branch, quarantine untouched */
__enic_open()
enables RQs and NAPI, issues CMD_ENABLE
... late vf_registered / mbox_send_disabled check
Any NAPI poll between CMD_ENABLE and the late check, for example busy poll,
passes this check in enic_rq_indicate_buf():
if (unlikely(READ_ONCE(enic->vf_rx_quarantined))) {
and delivers frames to the stack.
The enic.h comment says the flag "keeps the RX hot path fail-closed while
VF registration is lost or receive state may not match the PF". The commit
message says "Keep VF carrier off and receive delivery quarantined until
the final open-time mailbox check succeeds".
Should the reset paths, or enic_admin_chan_reopen(), set vf_rx_quarantined
to true when they drop the registration?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-b4-enic-sriov-v2-vf-receive-control-v4-0-5858d5a9ecb1%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v4 4/6] enic: validate V2 VF configuration replies
2026-11-30 13:58 ` [PATCH net-next v4 4/6] enic: validate V2 VF configuration replies Satish Kharat
@ 2026-12-01 14:04 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 14:04 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
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 warning in enic_mbox_vf_capability_check()
(drivers/net/ethernet/cisco/enic/enic_mbox.c) still says 'MBOX: PF…
--
enic: validate V2 VF configuration replies
This patch adds VF-side V2 mailbox operations for MAC filters and
packet-filter settings, plus the administrative-MAC protocol definitions.
It validates reply framing, echoed operations, result counts and applied
filter flags. Malformed replies and registration loss now force a VF
reconnect, and the patch adds a per-request mbox_reply_status that the
existing capability, register and unregister callers now check.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_mbox.c b/drivers/net/ethernet/cisco/enic/enic_mbox.c
> index 3579d2980a246..5afb45033772b 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_mbox.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_mbox.c
[ ... ]
> @@ -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 (!ret_major) {
> + if (!status) {
> switch (reply_type) {
> case ENIC_MBOX_VF_CAPABILITY_REPLY: {
> struct enic_mbox_vf_capability_reply_msg *cap = payload;
[ ... ]
> @@ -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,
[Severity: Low]
Is the warning text that follows this check still accurate?
It currently reads:
netdev_warn(enic->netdev,
"MBOX: PF rejected capability request or reported unsupported version %u\n",
version);
Before this patch, a PF rejection (nonzero ret_major) left pf_cap_version
at 0. That case reached this warning and returned -EOPNOTSUPP.
Now enic_mbox_vf_handle_reply() passes ret_major through
enic_mbox_vf_classify_reply(). It stores the result in mbox_reply_status
and skips the pf_cap_version write. The new "if (status) return status;"
then returns -EIO, -ENODEV or -EOPNOTSUPP before the version check, and
nothing is printed at this site.
This means the warning only fires when the PF accepted the request but
reported a version below ENIC_MBOX_CAP_VERSION_1. The "PF rejected
capability request" part can no longer happen. Rejections are still
logged by the "PF rejected reply type %u" warning in
enic_mbox_vf_handle_reply().
Should this message be reduced to just the unsupported version case? As
far as I can tell, the same wording is still there at the end of the
series.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-b4-enic-sriov-v2-vf-receive-control-v4-0-5858d5a9ecb1%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v4 5/6] enic: manage V2 VF station and administrative MAC
2026-11-30 13:58 ` [PATCH net-next v4 5/6] enic: manage V2 VF station and administrative MAC Satish Kharat
@ 2026-12-01 14:04 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 14:04 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
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] This patch changes the address-assignment type that userspace
sees for a V2 VF with a provisioned (nonzero) MAC, and the commit…
- [Low] Several new on-stack MAC buffers are plain `u8[ETH_ALEN]` arrays
with no `__aligned(2)`.
- [Low] This patch adds two driver paths that rewrite netdev->dev_addr in
place on a registered netdev while holding only RTNL.
--
enic: manage V2 VF station and administrative MAC
This patch moves the V2 VF station address onto the mailbox MAC
operation and treats the PF administrative MAC as authoritative. PF
notifications are handled in a delayed worker, and policy is refreshed
with CMD_GET_MAC_ADDR after registration. The station address is
installed on open and removed on ordinary stop, and perm_addr is
initialized from the address chosen at probe.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 9c4b94a949809..a2186f65c74a8 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
[ ... ]
> @@ -1064,6 +1067,501 @@ static int enic_set_mac_addr(struct net_device *netdev, char *addr)
[ ... ]
> +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];
[Severity: Low]
Should policy[] and selected[] be marked __aligned(2)?
They are passed to ether_addr_copy(), ether_addr_equal() and
eth_hw_addr_set(). include/linux/etherdevice.h documents
ether_addr_copy() with:
* Please note: dst & src must both be aligned to u16.
Without CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS, both ether_addr_copy()
and ether_addr_equal() access the address through u16 pointer casts. A
plain u8[ETH_ALEN] stack array is only guaranteed byte alignment. ENIC
depends only on PCI, so it can be built for strict-alignment
architectures, where this can trap or need slow fixups.
The same applies to previous_policy[], random_addr[], selected[] and
policy[] in enic_vf_admin_mac_refresh().
This patch already adds __aligned(2) to requested[] in
enic_vf_station_addr_open() and to enic->vf_station_addr. These other
arrays still lack the annotation at the end of the series.
> + unsigned long delay = 0;
> + u32 generation = 0;
[ ... ]
> + changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> + enic_vf_station_sync_reset(enic);
> + eth_hw_addr_set(enic->netdev, selected);
[Severity: Low]
Can a concurrent reader see a torn MAC address here?
This worker runs asynchronously after ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF.
It rewrites dev_addr in place on a registered netdev while holding only
RTNL:
enic_mbox_vf_handle_admin_mac()
enic_vf_admin_mac_notify()
enic_vf_admin_mac_work()
eth_hw_addr_set()
__dev_addr_set() /* memcpy into dev->dev_addr */
The core readers don't take RTNL. netif_get_mac_address()
(SIOCGIFHWADDR) and address_show() (/sys/class/net/*/address) take only
down_read(&dev_addr_sem) and rcu_read_lock(). The core writers
dev_set_mac_address_user() and do_setlink() take
down_write(&dev_addr_sem) for exactly this reason.
Those two lock sets don't overlap. A reader that runs during a PF-driven
change could therefore return a mix of old and new address bytes.
enic_vf_admin_mac_refresh() does the same thing when called from
__enic_open() and enic_admin_chan_reopen(). dev_addr_sem is declared
only in the private net/core/dev.h, so the driver can't simply take it.
[ ... ]
> +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: Low]
Is this change to addr_assign_type intended for a provisioned VF MAC?
enic_probe() now calls enic_vf_admin_mac_refresh() before
register_netdev(). For any nonzero CMD_GET_MAC_ADDR value, this sets
NET_ADDR_SET. Probe then copies dev_addr into perm_addr by hand:
enic_probe() {
...
/* Record the initial address while preserving how it was assigned. */
ether_addr_copy(netdev->perm_addr, netdev->dev_addr);
...
}
Before this patch, enic_get_vnic_config() read the same firmware MAC and
installed it with eth_hw_addr_set(). addr_assign_type stayed at
NET_ADDR_PERM, and register_netdevice() filled perm_addr.
/sys/class/net/<if>/addr_assign_type now changes from 0 to 3 for an
address that nothing set through dev_set_mac_address(). The UAPI
describes NET_ADDR_SET as "address is set using dev_set_mac_address()".
Userspace that trusts only NET_ADDR_PERM addresses behaves differently.
For example, systemd's net_id builtin stops producing ID_NET_NAME_MAC.
With a zero policy, perm_addr is a newly generated random address on
every probe. ETHTOOL_GPERMADDR then reports a different permanent
address each time the driver loads.
The commit message does disclose the random case:
Initialize perm_addr from the selected probe address while retaining its
assignment type, including NET_ADDR_RANDOM for a generated address.
It doesn't mention that a provisioned address changes from PERM to SET.
Could the commit message describe that change, or should the
provisioned case keep NET_ADDR_PERM?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-b4-enic-sriov-v2-vf-receive-control-v4-0-5858d5a9ecb1%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v4 6/6] enic: configure V2 VF receive mode over mailbox
2026-11-30 13:58 ` [PATCH net-next v4 6/6] enic: configure V2 VF receive mode over mailbox Satish Kharat
@ 2026-12-01 14:04 ` netdev-bot+sashiko
0 siblings, 0 replies; 12+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 14:04 UTC (permalink / raw)
To: satishkh
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, willemb,
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] enic_vf_sync_mac_filters() treats every SKIPPED DELETE result
as lost state.
- [Medium] An ADD the PF rejects permanently is never recorded.
- [Medium] A PF result of ENIC_MAC_ADDR_FLAG_OVERFLOW (PF exact-filter
table full) for a secondary-address ADD is handled the same way as a…
- [Low] The commit message says the patch will "Report policy denials
during open and runtime updates", but default builds report nothing.
--
enic: configure V2 VF receive mode over mailbox
This commit adds an asynchronous receive-mode callback for V2 VFs. The
callback programs unicast/multicast exact filters and packet-filter modes
through the PF mailbox. It orders broad-mode transitions around exact-filter
updates, tracks per-address results, and schedules a receive-mode replay
after an internal reopen.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index a2186f65c74a8..4a9b4bf9e16b8 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
[ ... ]
> @@ -1653,17 +1655,419 @@ static int enic_set_mac_address(struct net_device *netdev, void *p)
[ ... ]
> +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");
> +}
[Severity: Low]
The commit message says:
"Report policy denials during open and runtime updates."
Does netdev_dbg() meet that? Without DEBUG or CONFIG_DYNAMIC_DEBUG it
compiles to if (0), and with dynamic debug it is off by default. A PF
refusal of CMD_PFILTER_PROMISCUOUS or CMD_PFILTER_ALL_MULTICAST would leave
no trace on the VF.
Per-address ADD denials are not reported at any level either.
enic_vf_sync_mac_filters() folds NOT_PERMITTED, INVALID and OVERFLOW into
-EACCES, and enic_set_vf_rx_mode() turns that into success:
err = enic_vf_sync_mac_filters(enic, uc, mc);
if (err == -EACCES) {
...
err = 0;
}
So "ip link set ... promisc on" or a multicast join appears to succeed, and
the netdev shows PROMISC/ALLMULTI, while the PF has not applied it.
Would a netdev_info() or netdev_warn() (possibly rate limited) fit the
commit message better?
[ ... ]
> +static int enic_vf_sync_mac_filters(struct enic *enic,
> + struct netdev_hw_addr_list *uc,
> + struct netdev_hw_addr_list *mc)
> +{
[ ... ]
> + 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]
Can a pure policy denial trigger a full VF reset here?
Every SKIPPED DELETE sets reconnect. Below, that leads to
enic_mbox_vf_require_reconnect(), which kicks vf_mbox_recovery_work and ends
in enic_hang_reset(enic, true): full datapath stop, re-registration and
reopen.
The station path in this series documents a PF reply where every DELETE is
SKIPPED because an ADD in the same request was rejected. From
enic_vf_station_addr_replace():
/* A policy-rejected ADD can be reported with all preceding DELETEs
* skipped. No operation changed state in that coherent result tuple.
*/
The "enic: manage V2 VF station and administrative MAC" commit message
also says "If the PF skips every station DELETE and rejects the ADD as not
permitted...".
A receive-mode batch puts the stale DELETEs first and the ADDs after them.
Suppose installed address X is removed while PF-denied address Y is
pending. The batch is [DELETE X, ADD Y], and the PF could answer
DELETE X = SKIPPED and ADD Y = NOT_PERMITTED. Nothing changed on the PF,
but the VF still goes through a hang reset.
Y is never recorded (its sync_cnt stays 0), so it is collected again in
every later batch. Would any later address removal while Y is still listed
repeat the reset? Unprivileged sockets can join and leave multicast groups,
so if the PF denies an MC ADD this could be triggered over and over.
This depends on the out-of-tree PF using the same reply shape for
secondary-address batches as for station operations. Should the
{all DELETEs SKIPPED, ADD permanently rejected} result be treated as "no
state change", as enic_vf_station_addr_replace() does?
> + if (flags & ENIC_MAC_ADDR_FLAG_PERMANENT_MASK) {
> + if (add)
> + permanent_add = true;
> + else
> + reconnect = true;
> + continue;
> + }
[Severity: Medium]
Is ENIC_MAC_ADDR_FLAG_OVERFLOW meant to be handled like a policy denial
here?
ENIC_MAC_ADDR_FLAG_PERMANENT_MASK in enic_mbox.h groups OVERFLOW with
NOT_PERMITTED and INVALID:
#define ENIC_MAC_ADDR_FLAG_PERMANENT_MASK \
(ENIC_MAC_ADDR_FLAG_OVERFLOW | ENIC_MAC_ADDR_FLAG_NOT_PERMITTED | \
ENIC_MAC_ADDR_FLAG_INVALID)
So when the PF reports its exact-filter table as full for an ADD, the code
sets permanent_add and returns -EACCES, and enic_set_vf_rx_mode() turns
that into success.
The packet-filter flags come only from the driver's own counts:
enic_vf_uc_needs_promisc() triggers above 31 UC entries, and
enic_rx_mode_to_pkt_filter() above 32 MC entries. No PROMISCUOUS or
ALL_MULTICAST fallback is requested for a PF-reported overflow.
If the PF's real capacity or occupancy is smaller than the driver's model,
frames for that address are silently dropped. Examples are an IPv6
solicited-node multicast or a macvlan unicast. The same ADD is then resent
and ignored on every later rx-mode event.
The commit message says:
"leaving overflow entries unsynchronized for later convergence"
That appears to cover only driver-side overflow, where broad coverage is
requested. Should a PF-reported OVERFLOW also request broad coverage for
that address class?
[ ... ]
> + if (reconnect) {
> + enic_mbox_vf_require_reconnect(enic);
> + err = -EIO;
> + } else if (err != -EIO) {
> + /* Do not let a retryable or permanently-denied ADD overwrite an
> + * installed-filter counter inconsistency (-EIO) detected above.
> + */
> + if (retryable_add)
> + err = -EAGAIN;
> + else if (permanent_add)
> + err = -EACCES;
> + }
[Severity: Medium]
Does this precedence let a stable ADD denial use up the core retry budget?
A permanently denied ADD is never recorded, so its sync_cnt stays 0 and
enic_vf_collect_mac_ops() collects it again on every run:
if (add) {
if (ha->sync_cnt || *projected_count >= max_filters)
continue;
The PF may report the other operations in that request as SKIPPED, the
shape handled in enic_vf_station_addr_replace(). Then both permanent_add
and retryable_add are set, and the function returns -EAGAIN rather than
-EACCES.
enic_set_vf_rx_mode() converts only -EACCES to 0. It returns -EAGAIN before
the trailing packet-filter step, and the core retries via
netif_rx_mode_schedule_retry(). Each retry resends the same batch and gets
the same result until the limit is hit:
if (dev->rx_mode_retry_count >= NETIF_RX_MODE_RETRY_MAX) {
netdev_err(dev, "rx_mode retry limit reached, giving up\n");
The valid addresses that were SKIPPED in that batch are never installed.
The same thing repeats on every later address-list event while the denied
MAC stays listed. That seems to contradict the commit message:
"stable ADD policy denials do not consume the retry budget"
The ADD-only replay after a reconnect (see the SKIPPED DELETE question
above) would land in this same loop.
As with the previous question, this depends on PF reply behaviour that is
only inferred from the station path.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-b4-enic-sriov-v2-vf-receive-control-v4-0-5858d5a9ecb1%40cisco.com
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-01 14:04 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 13:58 [PATCH net-next v4 0/6] enic: add V2 VF receive control over MBOX Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 1/6] net: add netif_rx_mode_schedule_update() Satish Kharat
2026-11-30 13:58 ` [PATCH net-next v4 2/6] enic: serialize V2 VF mailbox requests Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 3/6] enic: recover V2 VF mailbox after request failure Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 4/6] enic: validate V2 VF configuration replies Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 5/6] enic: manage V2 VF station and administrative MAC Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
2026-11-30 13:58 ` [PATCH net-next v4 6/6] enic: configure V2 VF receive mode over mailbox Satish Kharat
2026-12-01 14:04 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox