From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5D903D9552 for ; Fri, 14 Aug 2026 02:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786673678; cv=none; b=Ls+y7JoEGo/wx0JxjAJvN3ImP26WYKoI5cROD0K8pTiqKUjI67DYSl5UB8qk7AuIxO/1w1E7O8jaK2VFeY4NskBZ43fkENaK1htG+lJexcETSg32BI7CwlSOyudNxOr0HjnLETFzI5FDCzgz4igvOGCfZcd0Ib/WKvbyhlLLp3Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786673678; c=relaxed/simple; bh=H6KDukLOvLt3/p2nEcWrQisGwKiiu5YkBa5HLIQqX20=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EFg2ZGk5sEYUAU5xYftbnNZjHrGqWvjcXjuPkXhEaEatkhUvk2FWPR+EkSFZIrZighK3nqXOoiDIyjdJe7xZS3MqdvHyPxDTp8ulbDF/FxOv9iXTLvvB8u0kbFCtFo23865ET+cjTOr33igyMWVUb0p4VSbMCLT/Fv7TU32aSek= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DQbu/sUv; arc=none smtp.client-ip=209.85.210.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DQbu/sUv" Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-848662cd2a1so460407b3a.2 for ; Thu, 13 Aug 2026 19:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786673673; x=1787278473; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+ZA1jnJL3YI7cMGEg+oraVpVLco86l/qR/NiEMlar0c=; b=DQbu/sUvtRrhE9hba48TzpjVG7z2a16B7QuV7P3FfyCvrLQl8SZJTEXmrqoaLw/eqM eCFaXO6omJtw5Ui+sODnCKwUvGDwDKICGbdW4pJ+vMfTkFy8CGga3zS45yjDWtnOhW1k Pa1ceGgmGv+Gx6jBFWm9SrxJmgRRoFc4bJsk2AKPf9uMNmGDsq5b6TTNSzi0hBDzEt/E FVEXz3FFcGyploQrNVqyhAGfvQlC8W5HTwCZtfWDIkpg5MW1v7JafxUOi25aIa6ocOho psaB47eb0BDdNw51+4e+pQH3QTv5Go4wGYL6QEZjzQCrd1exQ/1BElAqJROY4+NpA27L tMkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786673673; x=1787278473; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+ZA1jnJL3YI7cMGEg+oraVpVLco86l/qR/NiEMlar0c=; b=kUhqMi15RKpRe9gZ6sKfctLs+7sEc6HGaWGdXofXWUGbZ+9/bVtbntldRG//G0gAjT r1a2liMKx2TwSOTinXjC9c4yfAZMCPMmI0EXCBpB1ZunBZY9qg7rp0gPAPBQ1jhz3trx 1GRnDZF0dvyQQCqnPVC5mEP1d3zEnaE+XpY6Z0j5ULtsKaMKTeh7YhRM28YuJtX2PkAK jkuWAeNoIKlSbpZv4RQvVMItLkvdxyQu3agjlQ2ZyN++QNVRYZO+j1n/zuMW2mU3pTfn XInrHLh3AUHaVFhuiglp7msBeA1j8Ce8+dRCdf3Iefltl2SkRl8+PU7SRmCfyYAl29OF WNfA== X-Forwarded-Encrypted: i=1; AHgh+RoNKV2ga1KNfDvnTHziS2Jxg0NYjyj48gy1dhfQj7+PCnZA5f6n6g5qxc2yyvQMoGnXMzUVg492LtXyiKI=@vger.kernel.org X-Gm-Message-State: AOJu0YzRLBjLnAviur5gE0mol+w0up4qNsGas7/Bj8tpSFQ54vQnJkEn 7SRDRK5LpFO3eP4ndtpwCKbPaTpNbAF3wt1IgfTC58B9u3It4+MxBB9ilkJCdF/qO424f+G0aXb Q0hEkyjZgBZH0NkCT6ms/5L2VNA== X-Received: from pfhz14.prod.google.com ([2002:a05:6a00:240e:b0:847:84b8:2dcf]) (user=hramamurthy job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:f07:b0:847:9c06:2bef with SMTP id d2e1a72fcca58-84fde3e691cmr2540861b3a.29.1786673672646; Thu, 13 Aug 2026 19:14:32 -0700 (PDT) Date: Fri, 14 Aug 2026 02:14:05 +0000 In-Reply-To: <20260814021406.3044324-1-hramamurthy@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260814021406.3044324-1-hramamurthy@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814021406.3044324-16-hramamurthy@google.com> Subject: [PATCH net-next v4 15/15] gve: add link status/speed ctrl ops From: Harshitha Ramamurthy To: netdev@vger.kernel.org Cc: joshwash@google.com, hramamurthy@google.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, jordanrhee@google.com, willemb@google.com, nktgrg@google.com, maolson@google.com, thostet@google.com, jacob.e.keller@intel.com, przemyslaw.kitszel@intel.com, debarghyak@google.com, kees@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" From: Joshua Washington Refactor link status check to use a control plane op. Introduce new op for retrieving the link status in AQ mode. This op reads the link status from the device status register and stores the value in priv. Also add an op for retrieving link speed in AQ mode which calls into gve_adminq_report_link_speed. Reviewed-by: Willem de Bruijn Reviewed-by: Jordan Rhee Signed-off-by: Joshua Washington Signed-off-by: Harshitha Ramamurthy --- v3: - Fix kdoc typo ("set link status" -> "set link speed") - Copy link status into local variable instead of reading twice to prevent TOCTOU issue. drivers/net/ethernet/google/gve/gve.h | 5 ++++ drivers/net/ethernet/google/gve/gve_adminq.c | 10 +++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 1 + drivers/net/ethernet/google/gve/gve_ethtool.c | 3 +-- drivers/net/ethernet/google/gve/gve_main.c | 26 ++++++++++++------- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index f3906be810d8..3a50e7f7a2e7 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -847,6 +847,8 @@ struct gve_device_info { * @reset_flow_rules: Flush all flow rules from device * @create_queues: Sends commands to the device to create TX/RX queues. * @destroy_queues: Sends commands to the device to destroy TX/RX queues. + * @report_link_status: Set link status into @priv->link_up + * @report_link_speed: Set link speed into @priv->link_speed */ struct gve_ctrl_ops { int (*map_db_bar)(struct gve_priv *priv); @@ -867,6 +869,8 @@ struct gve_ctrl_ops { int (*reset_flow_rules)(struct gve_priv *priv); int (*create_queues)(struct gve_priv *priv); int (*destroy_queues)(struct gve_priv *priv); + int (*report_link_status)(struct gve_priv *priv); + int (*report_link_speed)(struct gve_priv *priv); }; struct gve_priv { @@ -968,6 +972,7 @@ struct gve_priv { /* Gvnic device link speed from hypervisor. */ u64 link_speed; + bool link_up; bool up_before_suspend; /* True if dev was up before suspend */ bool mgmt_irq_requested; diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 3635e81e936a..97071bfd8078 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -1839,3 +1839,13 @@ int gve_adminq_create_queues(struct gve_priv *priv) return err; } + +int gve_adminq_report_link_status(struct gve_priv *priv) +{ + u32 status; + + status = ioread32be(&priv->reg_bar0->device_status); + WRITE_ONCE(priv->link_up, + !!(GVE_DEVICE_STATUS_LINK_STATUS_MASK & status)); + return 0; +} diff --git a/drivers/net/ethernet/google/gve/gve_adminq.h b/drivers/net/ethernet/google/gve/gve_adminq.h index d696e4932a8b..8daac5fd685a 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.h +++ b/drivers/net/ethernet/google/gve/gve_adminq.h @@ -643,6 +643,7 @@ int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len, dma_addr_t stats_report_addr, u64 interval); int gve_adminq_verify_driver_compatibility(struct gve_priv *priv); int gve_adminq_get_device_properties(struct gve_priv *priv); +int gve_adminq_report_link_status(struct gve_priv *priv); int gve_adminq_report_link_speed(struct gve_priv *priv); int gve_adminq_add_flow_rule(struct gve_priv *priv, struct gve_adminq_flow_rule *rule, u32 loc); int gve_adminq_del_flow_rule(struct gve_priv *priv, u32 loc); diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c index dd1c44fedc77..a3220c651438 100644 --- a/drivers/net/ethernet/google/gve/gve_ethtool.c +++ b/drivers/net/ethernet/google/gve/gve_ethtool.c @@ -749,12 +749,11 @@ static int gve_get_link_ksettings(struct net_device *netdev, int err = 0; if (priv->link_speed == 0) - err = gve_adminq_report_link_speed(priv); + err = priv->ctrl_ops->report_link_speed(priv); cmd->base.speed = priv->link_speed; cmd->base.duplex = DUPLEX_FULL; - return err; } diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 500247b0e34a..800e1104d01b 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1504,15 +1504,18 @@ static int gve_close(struct net_device *dev) return err; } -static void gve_handle_link_status(struct gve_priv *priv, bool link_status) +static void gve_handle_link_status(struct gve_priv *priv) { + bool link_up; + if (!gve_get_napi_enabled(priv)) return; - if (link_status == netif_carrier_ok(priv->dev)) + link_up = READ_ONCE(priv->link_up); + if (link_up == netif_carrier_ok(priv->dev)) return; - if (link_status) { + if (link_up) { netdev_info(priv->dev, "Device link is up.\n"); netif_carrier_on(priv->dev); } else { @@ -1539,7 +1542,6 @@ static int gve_set_xdp(struct gve_priv *priv, struct bpf_prog *prog, { struct bpf_prog *old_prog; int err = 0; - u32 status; old_prog = READ_ONCE(priv->xdp_prog); if (!netif_running(priv->dev)) { @@ -1566,8 +1568,8 @@ static int gve_set_xdp(struct gve_priv *priv, struct bpf_prog *prog, bpf_prog_put(old_prog); out: - status = ioread32be(&priv->reg_bar0->device_status); - gve_handle_link_status(priv, GVE_DEVICE_STATUS_LINK_STATUS_MASK & status); + priv->ctrl_ops->report_link_status(priv); + gve_handle_link_status(priv); return err; } @@ -2000,11 +2002,11 @@ static void gve_turnup(struct gve_priv *priv) static void gve_turnup_and_check_status(struct gve_priv *priv) { - u32 status; + const struct gve_ctrl_ops *ops = priv->ctrl_ops; gve_turnup(priv); - status = ioread32be(&priv->reg_bar0->device_status); - gve_handle_link_status(priv, GVE_DEVICE_STATUS_LINK_STATUS_MASK & status); + ops->report_link_status(priv); + gve_handle_link_status(priv); } static struct gve_notify_block *gve_get_tx_notify_block(struct gve_priv *priv, @@ -2328,12 +2330,14 @@ static void gve_service_task(struct work_struct *work) { struct gve_priv *priv = container_of(work, struct gve_priv, service_task); + const struct gve_ctrl_ops *ops = priv->ctrl_ops; u32 status = ioread32be(&priv->reg_bar0->device_status); gve_handle_status(priv, status); gve_handle_reset(priv); - gve_handle_link_status(priv, GVE_DEVICE_STATUS_LINK_STATUS_MASK & status); + ops->report_link_status(priv); + gve_handle_link_status(priv); } static void gve_set_netdev_xdp_features(struct gve_priv *priv) @@ -2460,6 +2464,8 @@ static const struct gve_ctrl_ops gve_adminq_ops = { .teardown_mgmt_irq = gve_adminq_teardown_mgmt_irq, .create_queues = gve_adminq_create_queues, .destroy_queues = gve_adminq_destroy_queues, + .report_link_status = gve_adminq_report_link_status, + .report_link_speed = gve_adminq_report_link_speed, }; static int gve_init_priv(struct gve_priv *priv) -- 2.55.0.691.gc56d675ccc-goog