From patchwork Thu Apr 3 18:18:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 14036974 X-Patchwork-Delegate: kuba@kernel.org Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DD8F252917 for ; Thu, 3 Apr 2025 18:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743704371; cv=none; b=XkaNJzRwfIW87N5vc+8bIxwcgfoaPhqol8JroxRbD9QeA4p0bL++/damoo1BY3WaafKV2o0wvsFxiAthXmgorMQiIKlqc8cv79K/AKv0Lf0cv87It7UNWkpY+52r6CTYTRV7dENqJs9MVasBsAlVGxAEZ0A2G3IK7TJwKxurBqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743704371; c=relaxed/simple; bh=GBK9PN/yYYH+gk2hJu+YIaVba+T0W8d/4DGGlJZ5c2c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VFji+8NFLYYFHJoduMeWO80gYyHNqWsvQ2uSadkztiXcYaKAa37Izxkj+YZbJI3JAToOFaUD4AVNB4kOGr6x+YZ7qlxVkvMVqYR1XAdbIqa7HXY+Ies4OTcmLZG7wKRFEYP/4T72x5IMMICa8J+sJZJlubUwg6Wgl1fBX5LgAUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PRmPttYN; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PRmPttYN" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1743704367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hluZSQhV4YZGerB21D3gvvzkdMOqONtWzt8GVVUAIgU=; b=PRmPttYNb+eX46JetGTLf7wjvrxFNwWkEC4gU1rr72Rf1Xsl3Vr8XDk3vkHHEVWWwUkL3l asO3f7lhdKNK5UH0EYnb2XvXAAajRBaZ92HcsCrDvDvEgU+5/bYmFF3fmEKjwXiVLeWn3W FqGFNmcOC7rGZJKGbTy4MST323ufFZs= From: Sean Anderson To: netdev@vger.kernel.org, Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: linux-kernel@vger.kernel.org, Christian Marangi , upstream@airoha.com, Heiner Kallweit , Sean Anderson Subject: [RFC net-next PATCH 02/13] net: phylink: Support setting PCS link change callbacks Date: Thu, 3 Apr 2025 14:18:56 -0400 Message-Id: <20250403181907.1947517-3-sean.anderson@linux.dev> In-Reply-To: <20250403181907.1947517-1-sean.anderson@linux.dev> References: <20250403181907.1947517-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Support changing the link change callback, similar to how PHYs do it. This will allow the PCS wrapper to forward link changes to the wrapped PCS. Signed-off-by: Sean Anderson --- drivers/net/phy/phylink.c | 24 +++++++----------------- include/linux/phylink.h | 27 ++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 69ca765485db..76ce96315c0c 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1205,6 +1205,8 @@ static void phylink_pcs_neg_mode(struct phylink *pl, struct phylink_pcs *pcs, pl->act_link_an_mode = mode; } +static void pcs_change_callback(void *priv, bool up); + static void phylink_major_config(struct phylink *pl, bool restart, const struct phylink_link_state *state) { @@ -1260,10 +1262,10 @@ static void phylink_major_config(struct phylink *pl, bool restart, phylink_pcs_disable(pl->pcs); if (pl->pcs) - pl->pcs->phylink = NULL; - - pcs->phylink = pl; + pl->pcs->link_change_priv = NULL; + pcs->link_change = pcs_change_callback; + pcs->link_change_priv = pl; pl->pcs = pcs; } @@ -2333,25 +2335,13 @@ void phylink_mac_change(struct phylink *pl, bool up) } EXPORT_SYMBOL_GPL(phylink_mac_change); -/** - * phylink_pcs_change() - notify phylink of a change to PCS link state - * @pcs: pointer to &struct phylink_pcs - * @up: indicates whether the link is currently up. - * - * The PCS driver should call this when the state of its link changes - * (e.g. link failure, new negotiation results, etc.) Note: it should - * not determine "up" by reading the BMSR. If in doubt about the link - * state at interrupt time, then pass true if pcs_get_state() returns - * the latched link-down state, otherwise pass false. - */ -void phylink_pcs_change(struct phylink_pcs *pcs, bool up) +static void pcs_change_callback(void *priv, bool up) { - struct phylink *pl = pcs->phylink; + struct phylink *pl = priv; if (pl) phylink_link_changed(pl, up, "pcs"); } -EXPORT_SYMBOL_GPL(phylink_pcs_change); static irqreturn_t phylink_link_handler(int irq, void *data) { diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 1f5773ab5660..a16282ae746d 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -441,7 +441,8 @@ struct phylink_pcs_ops; * @supported_interfaces: describing which PHY_INTERFACE_MODE_xxx * are supported by this PCS. * @ops: a pointer to the &struct phylink_pcs_ops structure - * @phylink: pointer to &struct phylink_config + * @link_change: callback for when the link changes + * @link_change_priv: first argument to @link_change * @poll: poll the PCS for link changes * @rxc_always_on: The MAC driver requires the reference clock * to always be on. Standalone PCS drivers which @@ -451,13 +452,14 @@ struct phylink_pcs_ops; * This structure is designed to be embedded within the PCS private data, * and will be passed between phylink and the PCS. * - * The @phylink member is private to phylink and must not be touched by - * the PCS driver. + * @link_change, @link_change_priv, and @rxc_always_on will be filled in by + * phylink. */ struct phylink_pcs { DECLARE_PHY_INTERFACE_MASK(supported_interfaces); const struct phylink_pcs_ops *ops; - struct phylink *phylink; + void (*link_change)(void *priv, bool up); + void *link_change_priv; bool poll; bool rxc_always_on; }; @@ -699,7 +701,22 @@ int phylink_set_fixed_link(struct phylink *, const struct phylink_link_state *); void phylink_mac_change(struct phylink *, bool up); -void phylink_pcs_change(struct phylink_pcs *, bool up); +/** + * phylink_pcs_change() - notify phylink of a change to PCS link state + * @pcs: pointer to &struct phylink_pcs + * @up: indicates whether the link is currently up. + * + * The PCS driver should call this when the state of its link changes + * (e.g. link failure, new negotiation results, etc.) Note: it should + * not determine "up" by reading the BMSR. If in doubt about the link + * state at interrupt time, then pass true if pcs_get_state() returns + * the latched link-down state, otherwise pass false. + */ +static inline void phylink_pcs_change(struct phylink_pcs *pcs, bool up) +{ + if (pcs->link_change) + pcs->link_change(pcs->link_change_priv, up); +} int phylink_pcs_pre_init(struct phylink *pl, struct phylink_pcs *pcs);